public class Selenide
extends java.lang.Object
open(String)
for opening the tested application page and
$(String)
for searching web elements.Constructor and Description |
---|
Selenide() |
Modifier and Type | Method and Description |
---|---|
static SelenideElement |
$(org.openqa.selenium.By seleniumSelector)
Locates the first element matching given CSS selector
ATTENTION! This method doesn't start any search yet!
|
static SelenideElement |
$(org.openqa.selenium.By seleniumSelector,
int index) |
static SelenideElement |
$(java.lang.String cssSelector)
Locates the first element matching given CSS selector
ATTENTION! This method doesn't start any search yet!
|
static SelenideElement |
$(java.lang.String cssSelector,
int index)
Locates the Nth element matching given criteria
ATTENTION! This method doesn't start any search yet!
|
static SelenideElement |
$(org.openqa.selenium.WebElement webElement)
Wrap standard Selenium WebElement into SelenideElement
to use additional methods like shouldHave(), selectOption() etc.
|
static SelenideElement |
$(org.openqa.selenium.WebElement parent,
org.openqa.selenium.By seleniumSelector)
Deprecated.
please use $(parent).$(By) which is the same
(method will not be removed until 4.x or later)
|
static SelenideElement |
$(org.openqa.selenium.WebElement parent,
org.openqa.selenium.By seleniumSelector,
int index)
Deprecated.
please use $(parent).$(By, int) which is the same
(method will not be removed until 4.x or later)
|
static SelenideElement |
$(org.openqa.selenium.WebElement parent,
java.lang.String cssSelector)
Deprecated.
please use $(parent).$(String) which is the same
(method will not be removed until 4.x or later)
|
static SelenideElement |
$(org.openqa.selenium.WebElement parent,
java.lang.String cssSelector,
int index)
Deprecated.
please use $(parent).$(String, int) which is the same
(method will not be removed until 4.x or later)
|
static ElementsCollection |
$$(org.openqa.selenium.By seleniumSelector)
Locates all elements matching given CSS selector.
|
static ElementsCollection |
$$(java.util.Collection<? extends org.openqa.selenium.WebElement> elements)
Initialize collection with Elements
|
static ElementsCollection |
$$(java.lang.String cssSelector)
Locates all elements matching given CSS selector.
|
static ElementsCollection |
$$(org.openqa.selenium.WebElement parent,
org.openqa.selenium.By seleniumSelector)
Deprecated.
please use $(parent).$$(By) which is the same
(method will not be removed until 4.x or later)
|
static ElementsCollection |
$$(org.openqa.selenium.WebElement parent,
java.lang.String cssSelector)
Deprecated.
please use $(parent).$$(String) which is the same
(method will not be removed until 4.x or later)
|
static ElementsCollection |
$$x(java.lang.String xpathExpression)
Locates all elements matching given XPATH expression.
|
static SelenideElement |
$x(java.lang.String xpathExpression)
Locates the first element matching given XPATH expression
ATTENTION! This method doesn't start any search yet!
|
static org.openqa.selenium.interactions.Actions |
actions()
With this method you can use Selenium Actions like described in the
AdvancedUserInteractions page.
|
static boolean |
atBottom()
Return true if bottom of the page is reached
Useful if you need to scroll down by x pixels unknown number of times.
|
static void |
back()
Navigate browser back to previous page
|
static void |
clearBrowserCookies()
Clear browser cookies.
|
static void |
clearBrowserLocalStorage()
Clear browser local storage.
|
static void |
close()
Deprecated.
Use either
closeWindow() or closeWebDriver() |
static void |
closeWebDriver()
Close the browser if it's open.
|
static void |
closeWindow()
Close the current window, quitting the browser if it's the last window currently open.
|
static java.lang.String |
confirm()
Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'alert' or 'confirm').
|
static java.lang.String |
confirm(java.lang.String expectedDialogText)
Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'alert' or 'confirm').
|
static java.lang.String |
dismiss()
Dismiss (click "No" or "Cancel") in the confirmation dialog (javascript 'alert' or 'confirm').
|
static java.lang.String |
dismiss(java.lang.String expectedDialogText)
Dismiss (click "No" or "Cancel") in the confirmation dialog (javascript 'alert' or 'confirm').
|
static java.io.File |
download(java.lang.String url)
Download file using a direct link.
|
static java.io.File |
download(java.lang.String url,
long timeoutMs)
Download file using a direct link.
|
static SelenideElement |
element(org.openqa.selenium.By seleniumSelector)
Locates the first element matching given CSS selector
ATTENTION! This method doesn't start any search yet!
|
static SelenideElement |
element(org.openqa.selenium.By seleniumSelector,
int index)
Locates the Nth element matching given criteria
ATTENTION! This method doesn't start any search yet!
|
static SelenideElement |
element(java.lang.String cssSelector)
Locates the first element matching given CSS selector
ATTENTION! This method doesn't start any search yet!
|
static SelenideElement |
element(java.lang.String cssSelector,
int index)
Locates the Nth element matching given criteria
ATTENTION! This method doesn't start any search yet!
|
static SelenideElement |
element(org.openqa.selenium.WebElement webElement)
Wrap standard Selenium WebElement into SelenideElement
to use additional methods like shouldHave(), selectOption() etc.
|
static ElementsCollection |
elements(org.openqa.selenium.By seleniumSelector)
Locates all elements matching given CSS selector.
|
static ElementsCollection |
elements(java.util.Collection<? extends org.openqa.selenium.WebElement> elements)
Wrap standard Selenium WebElement collection into SelenideElement collection
to use additional methods like shouldHave() etc.
|
static ElementsCollection |
elements(java.lang.String cssSelector)
Locates all elements matching given CSS selector.
|
static <T> T |
executeAsyncJavaScript(java.lang.String jsCode,
java.lang.Object... arguments) |
static <T> T |
executeJavaScript(java.lang.String jsCode,
java.lang.Object... arguments) |
static void |
forward()
Navigate browser forward to next page
|
static SelenideElement |
getElement(org.openqa.selenium.By criteria)
Deprecated.
please use element(criteria) which is the same
(method will not be removed until 4.x or later)
Locates the first element matching given criteria
ATTENTION! This method doesn't start any search yet!
|
static SelenideElement |
getElement(org.openqa.selenium.By criteria,
int index)
Deprecated.
please use element(criteria, index) which is the same
(method will not be removed until 4.x or later)
Locates the Nth element matching given criteria
ATTENTION! This method doesn't start any search yet!
|
static ElementsCollection |
getElements(org.openqa.selenium.By criteria)
Deprecated.
please use elements(criteria) which is the same
(method will not be removed until 4.x or later)
Locates all elements matching given CSS selector
ATTENTION! This method doesn't start any search yet!
|
static org.openqa.selenium.WebElement |
getFocusedElement() |
static SelenideElement |
getSelectedRadio(org.openqa.selenium.By radioField)
Returns selected element in radio group
|
static java.lang.String |
getUserAgent()
Get current user agent from browser session
|
static java.util.List<java.lang.String> |
getWebDriverLogs(java.lang.String logType)
Same as com.codeborne.selenide.Selenide#getWebDriverLogs(java.lang.String, java.util.logging.Level)
|
static java.util.List<java.lang.String> |
getWebDriverLogs(java.lang.String logType,
java.util.logging.Level logLevel)
Getting and filtering of the WebDriver logs for specified LogType by specified logging level
For example to get WebDriver Browser's console output (including JS info, warnings, errors, etc. |
static void |
open()
Open an empty browser (without opening any pages).
|
static void |
open(java.lang.String relativeOrAbsoluteUrl)
The main starting point in your tests.
|
static void |
open(java.lang.String relativeOrAbsoluteUrl,
AuthenticationType authenticationType,
Credentials credentials)
The main starting point in your tests.
|
static void |
open(java.lang.String relativeOrAbsoluteUrl,
AuthenticationType authenticationType,
java.lang.String login,
java.lang.String password)
The main starting point in your tests.
|
static <PageObjectClass> |
open(java.lang.String relativeOrAbsoluteUrl,
java.lang.Class<PageObjectClass> pageObjectClassClass)
Open a web page and create PageObject for it.
|
static void |
open(java.lang.String relativeOrAbsoluteUrl,
java.lang.String domain,
java.lang.String login,
java.lang.String password)
The main starting point in your tests.
|
static <PageObjectClass> |
open(java.lang.String relativeOrAbsoluteUrl,
java.lang.String domain,
java.lang.String login,
java.lang.String password,
java.lang.Class<PageObjectClass> pageObjectClassClass)
Open a web page using Basic Auth credentials and create PageObject for it.
|
static void |
open(java.net.URL absoluteUrl) |
static <PageObjectClass> |
open(java.net.URL absoluteUrl,
java.lang.Class<PageObjectClass> pageObjectClassClass)
Open a web page and create PageObject for it.
|
static void |
open(java.net.URL absoluteUrl,
java.lang.String domain,
java.lang.String login,
java.lang.String password) |
static <PageObjectClass> |
open(java.net.URL absoluteUrl,
java.lang.String domain,
java.lang.String login,
java.lang.String password,
java.lang.Class<PageObjectClass> pageObjectClassClass)
Open a web page using Basic Auth credentials and create PageObject for it.
|
static <PageObjectClass> |
page(java.lang.Class<PageObjectClass> pageObjectClass)
Create a Page Object instance
|
static <PageObjectClass,T extends PageObjectClass> |
page(T pageObject)
Initialize a given Page Object instance
|
static java.lang.String |
prompt()
Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'prompt').
|
static java.lang.String |
prompt(java.lang.String inputText)
Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'prompt').
|
static java.lang.String |
prompt(java.lang.String expectedDialogText,
java.lang.String inputText)
Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'prompt').
|
static void |
refresh()
Reload current page
|
static java.lang.String |
screenshot(java.lang.String fileName)
Take the screenshot of current page and save to file fileName.html and fileName.png
|
static void |
sleep(long milliseconds)
Not recommended.
|
static SelenideTargetLocator |
switchTo()
Switch to window/tab/frame/parentFrame/innerFrame/alert.
|
static java.lang.String |
title() |
static void |
updateHash(java.lang.String hash)
Update the hash of the window location.
|
static void |
using(org.openqa.selenium.WebDriver webDriver,
java.lang.Runnable lambda) |
static SelenideWait |
Wait()
Create a org.openqa.selenium.support.ui.FluentWait instance with Selenide timeout/polling.
|
static void |
zoom(double factor)
Zoom current page (in or out).
|
public static void open(java.lang.String relativeOrAbsoluteUrl)
relativeOrAbsoluteUrl
- If not starting with "http://" or "https://" or "file://", it's considered to be relative URL.
In this case, it's prepended by baseUrlpublic static void open(java.net.URL absoluteUrl)
open(String)
public static void open(java.lang.String relativeOrAbsoluteUrl, java.lang.String domain, java.lang.String login, java.lang.String password)
Open a browser window with given URL and credentials for basic authentication
If browser window was already opened before, it will be reused.
Don't bother about closing the browser - it will be closed automatically when all your tests are done.
If not starting with "http://" or "https://" or "file://", it's considered to be relative URL.
In this case, it's prepended by baseUrl
public static void open(java.lang.String relativeOrAbsoluteUrl, AuthenticationType authenticationType, java.lang.String login, java.lang.String password)
Open browser and pass authentication using build-in proxy.
A common authenticationType is "Basic". See Web HTTP reference for other types.
This method can only work if - Configuration.fileDownload == Configuration.FileDownloadMode.PROXY;
AuthenticationType
public static void open(java.lang.String relativeOrAbsoluteUrl, AuthenticationType authenticationType, Credentials credentials)
Open browser and pass authentication using build-in proxy.
A common authenticationType is "Basic". See Web HTTP reference for other types.
This method can only work if - Configuration.fileDownload == Configuration.FileDownloadMode.PROXY;
AuthenticationType
,
Credentials
public static void open(java.net.URL absoluteUrl, java.lang.String domain, java.lang.String login, java.lang.String password)
open(URL, String, String, String)
public static void open()
public static void using(org.openqa.selenium.WebDriver webDriver, java.lang.Runnable lambda)
public static void updateHash(java.lang.String hash)
hash
- value for window.location.hash - Accept either "#hash" or "hash".public static <PageObjectClass> PageObjectClass open(java.lang.String relativeOrAbsoluteUrl, java.lang.Class<PageObjectClass> pageObjectClassClass)
public static <PageObjectClass> PageObjectClass open(java.net.URL absoluteUrl, java.lang.Class<PageObjectClass> pageObjectClassClass)
public static <PageObjectClass> PageObjectClass open(java.lang.String relativeOrAbsoluteUrl, java.lang.String domain, java.lang.String login, java.lang.String password, java.lang.Class<PageObjectClass> pageObjectClassClass)
public static <PageObjectClass> PageObjectClass open(java.net.URL absoluteUrl, java.lang.String domain, java.lang.String login, java.lang.String password, java.lang.Class<PageObjectClass> pageObjectClassClass)
public static void closeWindow()
WebDriver.close()
public static void closeWebDriver()
Close the browser if it's open.
NB! Method quits this driver, closing every associated window.
WebDriver.quit()
@Deprecated public static void close()
closeWindow()
or closeWebDriver()
public static void refresh()
public static void back()
public static void forward()
@CheckReturnValue public static java.lang.String title()
public static void sleep(long milliseconds)
milliseconds
- Time to sleep in millisecondspublic static java.lang.String screenshot(java.lang.String fileName)
fileName
- Name of file (without extension) to save HTML and PNG to@CheckReturnValue public static SelenideElement $(org.openqa.selenium.WebElement webElement)
webElement
- standard Selenium WebElement@CheckReturnValue public static SelenideElement $(java.lang.String cssSelector)
cssSelector
- any CSS selector like "input[name='first_name']" or "#messages .new_message"@CheckReturnValue public static SelenideElement $x(java.lang.String xpathExpression)
xpathExpression
- any XPATH expression //*[@id='value'] //E[contains(@A, 'value')]@CheckReturnValue public static SelenideElement $(org.openqa.selenium.By seleniumSelector)
seleniumSelector
- any Selenium selector like By.id(), By.name() etc.@CheckReturnValue public static SelenideElement $(org.openqa.selenium.By seleniumSelector, int index)
getElement(By, int)
@Deprecated public static SelenideElement $(org.openqa.selenium.WebElement parent, java.lang.String cssSelector)
parent
- the WebElement to search elements incssSelector
- any CSS selector like "input[name='first_name']" or "#messages .new_message"Locates the first element matching given CSS selector
ATTENTION! This method doesn't start any search yet!
@CheckReturnValue public static SelenideElement $(java.lang.String cssSelector, int index)
cssSelector
- any CSS selector like "input[name='first_name']" or "#messages .new_message"index
- 0..N@Deprecated @CheckReturnValue public static SelenideElement $(org.openqa.selenium.WebElement parent, java.lang.String cssSelector, int index)
parent
- the WebElement to search elements incssSelector
- any CSS selector like "input[name='first_name']" or "#messages .new_message"index
- 0..NLocates the Nth element matching given criteria
ATTENTION! This method doesn't start any search yet!
@Deprecated @CheckReturnValue public static SelenideElement $(org.openqa.selenium.WebElement parent, org.openqa.selenium.By seleniumSelector)
parent
- the WebElement to search elements inseleniumSelector
- any Selenium selector like By.id(), By.name() etc.Locates the first element matching given criteria
ATTENTION! This method doesn't start any search yet!
@Deprecated @CheckReturnValue public static SelenideElement $(org.openqa.selenium.WebElement parent, org.openqa.selenium.By seleniumSelector, int index)
parent
- the WebElement to search elements inseleniumSelector
- any Selenium selector like By.id(), By.name() etc.index
- 0..NLocates the Nth element matching given criteria
ATTENTION! This method doesn't start any search yet!
@CheckReturnValue public static ElementsCollection $$(java.util.Collection<? extends org.openqa.selenium.WebElement> elements)
@CheckReturnValue public static ElementsCollection $$(java.lang.String cssSelector)
cssSelector
- any CSS selector like "input[name='first_name']" or "#messages .new_message"@CheckReturnValue public static ElementsCollection $$x(java.lang.String xpathExpression)
xpathExpression
- any XPATH expression //*[@id='value'] //E[contains(@A, 'value')]@CheckReturnValue public static ElementsCollection $$(org.openqa.selenium.By seleniumSelector)
seleniumSelector
- any Selenium selector like By.id(), By.name() etc.@Deprecated @CheckReturnValue public static ElementsCollection $$(org.openqa.selenium.WebElement parent, java.lang.String cssSelector)
parent
- the WebElement to search elements incssSelector
- any CSS selector like "input[name='first_name']" or "#messages .new_message"Locates all elements matching given CSS selector inside given parent element
ATTENTION! This method doesn't start any search yet!
Methods returns an ElementsCollection which is a list of WebElement objects that can be iterated,
and at the same time is implementation of WebElement interface,
meaning that you can call methods .sendKeys(), click() etc. on it.
@Deprecated @CheckReturnValue public static ElementsCollection $$(org.openqa.selenium.WebElement parent, org.openqa.selenium.By seleniumSelector)
@CheckReturnValue public static SelenideElement element(org.openqa.selenium.WebElement webElement)
webElement
- standard Selenium WebElement@CheckReturnValue public static SelenideElement element(java.lang.String cssSelector)
cssSelector
- any CSS selector like "input[name='first_name']" or "#messages .new_message"@CheckReturnValue public static SelenideElement element(org.openqa.selenium.By seleniumSelector)
seleniumSelector
- any Selenium selector like By.id(), By.name() etc.@CheckReturnValue public static SelenideElement element(org.openqa.selenium.By seleniumSelector, int index)
seleniumSelector
- any Selenium selector like By.id(), By.name() etc.index
- 0..N@CheckReturnValue public static SelenideElement element(java.lang.String cssSelector, int index)
cssSelector
- any CSS selector like "input[name='first_name']" or "#messages .new_message"index
- 0..N@CheckReturnValue public static ElementsCollection elements(java.util.Collection<? extends org.openqa.selenium.WebElement> elements)
elements
- standard Selenium WebElement collection@CheckReturnValue public static ElementsCollection elements(java.lang.String cssSelector)
cssSelector
- any CSS selector like "input[name='first_name']" or "#messages .new_message"@CheckReturnValue public static ElementsCollection elements(org.openqa.selenium.By seleniumSelector)
seleniumSelector
- any Selenium selector like By.id(), By.name() etc.@Deprecated @CheckReturnValue public static SelenideElement getElement(org.openqa.selenium.By criteria)
criteria
- instance of By: By.id(), By.className() etc.@Deprecated @CheckReturnValue public static SelenideElement getElement(org.openqa.selenium.By criteria, int index)
criteria
- instance of By: By.id(), By.className() etc.index
- 0..N@Deprecated @CheckReturnValue public static ElementsCollection getElements(org.openqa.selenium.By criteria)
criteria
- instance of By: By.id(), By.className() etc.public static <T> T executeJavaScript(java.lang.String jsCode, java.lang.Object... arguments)
JavascriptExecutor.executeScript(java.lang.String, java.lang.Object...)
public static <T> T executeAsyncJavaScript(java.lang.String jsCode, java.lang.Object... arguments)
JavascriptExecutor.executeAsyncScript(java.lang.String, java.lang.Object...)
@CheckReturnValue public static SelenideElement getSelectedRadio(org.openqa.selenium.By radioField)
public static java.lang.String confirm()
public static java.lang.String confirm(java.lang.String expectedDialogText)
expectedDialogText
- if not null, check that confirmation dialog displays this message (case-sensitive)DialogTextMismatch
- if confirmation message differs from expected messagepublic static java.lang.String prompt()
public static java.lang.String prompt(java.lang.String inputText)
inputText
- if not null, sets value in prompt dialog inputpublic static java.lang.String prompt(java.lang.String expectedDialogText, java.lang.String inputText)
expectedDialogText
- if not null, check that confirmation dialog displays this message (case-sensitive)inputText
- if not null, sets value in prompt dialog inputDialogTextMismatch
- if confirmation message differs from expected messagepublic static java.lang.String dismiss()
public static java.lang.String dismiss(java.lang.String expectedDialogText)
expectedDialogText
- if not null, check that confirmation dialog displays this message (case-sensitive)DialogTextMismatch
- if confirmation message differs from expected messagepublic static SelenideTargetLocator switchTo()
@CheckReturnValue public static org.openqa.selenium.WebElement getFocusedElement()
@CheckReturnValue public static <PageObjectClass> PageObjectClass page(java.lang.Class<PageObjectClass> pageObjectClass)
@CheckReturnValue public static <PageObjectClass,T extends PageObjectClass> PageObjectClass page(T pageObject)
@CheckReturnValue public static SelenideWait Wait()
Wait().until(invisibilityOfElementLocated(By.id("magic-id")));
@CheckReturnValue public static org.openqa.selenium.interactions.Actions actions()
actions() .sendKeys($(By.name("rememberMe")), "John") .click($(#rememberMe")) .click($(byText("Login"))) .build() .perform();
public static void zoom(double factor)
factor
- e.g. 1.1 or 2.0 or 0.5public static java.util.List<java.lang.String> getWebDriverLogs(java.lang.String logType)
public static java.util.List<java.lang.String> getWebDriverLogs(java.lang.String logType, java.util.logging.Level logLevel)
for(String logEntry : getWebDriverLogs(LogType.BROWSER, Level.ALL)) {
Reporter.log(logEntry + "<br>");
}
logType
- WebDriver supported log typeslogLevel
- logging level that will be used to control logging outputLogType
,
Level
public static void clearBrowserCookies()
public static void clearBrowserLocalStorage()
public static java.lang.String getUserAgent()
public static boolean atBottom()
public static java.io.File download(java.lang.String url) throws java.io.IOException
url
- either relative or absolute urljava.io.IOException
- if failed to download filepublic static java.io.File download(java.lang.String url, long timeoutMs) throws java.io.IOException
url
- either relative or absolute urltimeoutMs
- specific timeout in msjava.io.IOException
- if failed to download file