Class Selenide
- java.lang.Object
-
- com.codeborne.selenide.Selenide
-
public class Selenide extends java.lang.ObjectThe main starting point of Selenide. You start with methodsopen(String)for opening the tested application page and$(String)for searching web elements.
-
-
Constructor Summary
Constructors Constructor Description Selenide()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description 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.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$(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, 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 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 ElementsCollection$$(java.lang.String cssSelector)Locates all elements matching given CSS selector.static ElementsCollection$$(java.util.Collection<? extends org.openqa.selenium.WebElement> elements)Initialize collection with Elementsstatic ElementsCollection$$(org.openqa.selenium.By seleniumSelector)Locates all elements matching given CSS selector.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$$(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$$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.Actionsactions()With this method you can use Selenium Actions like described in the AdvancedUserInteractions page.static booleanatBottom()Return true if bottom of the page is reached Useful if you need to scroll down by x pixels unknown number of times.static voidback()Navigate browser back to previous pagestatic voidclearBrowserCookies()Clear browser cookies.static voidclearBrowserLocalStorage()Clear browser local storage.static voidclose()Deprecated.Use eithercloseWindow()orcloseWebDriver()static voidcloseWebDriver()Close the browser if it's open.static voidcloseWindow()Close the current window, quitting the browser if it's the last window currently open.static java.lang.Stringconfirm()Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'alert' or 'confirm').static java.lang.Stringconfirm(java.lang.String expectedDialogText)Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'alert' or 'confirm').static java.lang.Stringdismiss()Dismiss (click "No" or "Cancel") in the confirmation dialog (javascript 'alert' or 'confirm').static java.lang.Stringdismiss(java.lang.String expectedDialogText)Dismiss (click "No" or "Cancel") in the confirmation dialog (javascript 'alert' or 'confirm').static java.io.Filedownload(java.lang.String url)Download file using a direct link.static java.io.Filedownload(java.lang.String url, long timeoutMs)Download file using a direct link.static SelenideElementelement(java.lang.String cssSelector)Locates the first element matching given CSS selector ATTENTION! This method doesn't start any search yet!static SelenideElementelement(java.lang.String cssSelector, int index)Locates the Nth element matching given criteria ATTENTION! This method doesn't start any search yet!static SelenideElementelement(org.openqa.selenium.By seleniumSelector)Locates the first element matching given CSS selector ATTENTION! This method doesn't start any search yet!static SelenideElementelement(org.openqa.selenium.By seleniumSelector, int index)Locates the Nth element matching given criteria ATTENTION! This method doesn't start any search yet!static SelenideElementelement(org.openqa.selenium.WebElement webElement)Wrap standard Selenium WebElement into SelenideElement to use additional methods like shouldHave(), selectOption() etc.static ElementsCollectionelements(java.lang.String cssSelector)Locates all elements matching given CSS selector.static ElementsCollectionelements(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 ElementsCollectionelements(org.openqa.selenium.By seleniumSelector)Locates all elements matching given CSS selector.static <T> TexecuteAsyncJavaScript(java.lang.String jsCode, java.lang.Object... arguments)static <T> TexecuteJavaScript(java.lang.String jsCode, java.lang.Object... arguments)static voidforward()Navigate browser forward to next pagestatic SelenideElementgetElement(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 SelenideElementgetElement(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 ElementsCollectiongetElements(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.WebElementgetFocusedElement()static SelenideElementgetSelectedRadio(org.openqa.selenium.By radioField)Returns selected element in radio groupstatic java.lang.StringgetUserAgent()Get current user agent from browser sessionstatic 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 voidopen()Open an empty browser (without opening any pages).static voidopen(java.lang.String relativeOrAbsoluteUrl)The main starting point in your tests.static voidopen(java.lang.String relativeOrAbsoluteUrl, AuthenticationType authenticationType, Credentials credentials)The main starting point in your tests.static voidopen(java.lang.String relativeOrAbsoluteUrl, AuthenticationType authenticationType, java.lang.String login, java.lang.String password)The main starting point in your tests.static <PageObjectClass>
PageObjectClassopen(java.lang.String relativeOrAbsoluteUrl, java.lang.Class<PageObjectClass> pageObjectClassClass)Open a web page and create PageObject for it.static voidopen(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>
PageObjectClassopen(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 voidopen(java.net.URL absoluteUrl)static <PageObjectClass>
PageObjectClassopen(java.net.URL absoluteUrl, java.lang.Class<PageObjectClass> pageObjectClassClass)Open a web page and create PageObject for it.static voidopen(java.net.URL absoluteUrl, java.lang.String domain, java.lang.String login, java.lang.String password)static <PageObjectClass>
PageObjectClassopen(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>
PageObjectClasspage(java.lang.Class<PageObjectClass> pageObjectClass)Create a Page Object instancestatic <PageObjectClass,T extends PageObjectClass>
PageObjectClasspage(T pageObject)Initialize a given Page Object instancestatic java.lang.Stringprompt()Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'prompt').static java.lang.Stringprompt(java.lang.String inputText)Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'prompt').static java.lang.Stringprompt(java.lang.String expectedDialogText, java.lang.String inputText)Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'prompt').static voidrefresh()Reload current pagestatic java.lang.Stringscreenshot(java.lang.String fileName)Take the screenshot of current page and save to file fileName.html and fileName.pngstatic voidsleep(long milliseconds)Not recommended.static SelenideTargetLocatorswitchTo()Switch to window/tab/frame/parentFrame/innerFrame/alert.static java.lang.Stringtitle()static voidupdateHash(java.lang.String hash)Update the hash of the window location.static voidusing(org.openqa.selenium.WebDriver webDriver, java.lang.Runnable lambda)static SelenideWaitWait()Create a org.openqa.selenium.support.ui.FluentWait instance with Selenide timeout/polling.static voidzoom(double factor)Zoom current page (in or out).
-
-
-
Method Detail
-
open
public static void open(java.lang.String relativeOrAbsoluteUrl)
The main starting point in your tests. Open a browser window with given URL. 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.- Parameters:
relativeOrAbsoluteUrl- If not starting with "http://" or "https://" or "file://", it's considered to be relative URL. In this case, it's prepended by baseUrl
-
open
public static void open(java.net.URL absoluteUrl)
- See Also:
open(String)
-
open
public 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.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
-
open
public static void open(java.lang.String relativeOrAbsoluteUrl, AuthenticationType authenticationType, java.lang.String login, java.lang.String password)The main starting point in your tests.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;- See Also:
- Web HTTP reference,
AuthenticationType
-
open
public static void open(java.lang.String relativeOrAbsoluteUrl, AuthenticationType authenticationType, Credentials credentials)The main starting point in your tests.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;- See Also:
- Web HTTP reference,
AuthenticationType,Credentials
-
open
public static void open(java.net.URL absoluteUrl, java.lang.String domain, java.lang.String login, java.lang.String password)- See Also:
open(URL, String, String, String)
-
open
public static void open()
Open an empty browser (without opening any pages). E.g. useful for starting mobile applications in Appium.
-
using
public static void using(org.openqa.selenium.WebDriver webDriver, java.lang.Runnable lambda)
-
updateHash
public static void updateHash(java.lang.String hash)
Update the hash of the window location. Useful to navigate in ajax apps without reloading the page, since open(url) makes a full page reload.- Parameters:
hash- value for window.location.hash - Accept either "#hash" or "hash".
-
open
public static <PageObjectClass> PageObjectClass open(java.lang.String relativeOrAbsoluteUrl, java.lang.Class<PageObjectClass> pageObjectClassClass)Open a web page and create PageObject for it.- Returns:
- PageObject of given class
-
open
public static <PageObjectClass> PageObjectClass open(java.net.URL absoluteUrl, java.lang.Class<PageObjectClass> pageObjectClassClass)Open a web page and create PageObject for it.- Returns:
- PageObject of given class
-
open
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)Open a web page using Basic Auth credentials and create PageObject for it.- Returns:
- PageObject of given class
-
open
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)Open a web page using Basic Auth credentials and create PageObject for it.- Returns:
- PageObject of given class
-
closeWindow
public static void closeWindow()
Close the current window, quitting the browser if it's the last window currently open.- See Also:
WebDriver.close()
-
closeWebDriver
public static void closeWebDriver()
Close the browser if it's open.
NB! Method quits this driver, closing every associated window.
- See Also:
WebDriver.quit()
-
close
@Deprecated public static void close()
Deprecated.Use eithercloseWindow()orcloseWebDriver()
-
refresh
public static void refresh()
Reload current page
-
back
public static void back()
Navigate browser back to previous page
-
forward
public static void forward()
Navigate browser forward to next page
-
title
public static java.lang.String title()
- Returns:
- title of the page
-
sleep
public static void sleep(long milliseconds)
Not recommended. Test should not sleep, but should wait for some condition instead.- Parameters:
milliseconds- Time to sleep in milliseconds
-
screenshot
public static java.lang.String screenshot(java.lang.String fileName)
Take the screenshot of current page and save to file fileName.html and fileName.png- Parameters:
fileName- Name of file (without extension) to save HTML and PNG to- Returns:
- The name of resulting file
-
$
public static SelenideElement $(org.openqa.selenium.WebElement webElement)
Wrap standard Selenium WebElement into SelenideElement to use additional methods like shouldHave(), selectOption() etc.- Parameters:
webElement- standard Selenium WebElement- Returns:
- given WebElement wrapped into SelenideElement
-
$
public static SelenideElement $(java.lang.String cssSelector)
Locates the first element matching given CSS selector ATTENTION! This method doesn't start any search yet!- Parameters:
cssSelector- any CSS selector like "input[name='first_name']" or "#messages .new_message"- Returns:
- SelenideElement
-
$x
public static SelenideElement $x(java.lang.String xpathExpression)
Locates the first element matching given XPATH expression ATTENTION! This method doesn't start any search yet!- Parameters:
xpathExpression- any XPATH expression //*[@id='value'] //E[contains(@A, 'value')]- Returns:
- SelenideElement which locates elements via XPath
-
$
public static SelenideElement $(org.openqa.selenium.By seleniumSelector)
Locates the first element matching given CSS selector ATTENTION! This method doesn't start any search yet!- Parameters:
seleniumSelector- any Selenium selector like By.id(), By.name() etc.- Returns:
- SelenideElement
-
$
public static SelenideElement $(org.openqa.selenium.By seleniumSelector, int index)
- See Also:
getElement(By, int)
-
$
@Deprecated public 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)- Parameters:
parent- the WebElement to search elements incssSelector- any CSS selector like "input[name='first_name']" or "#messages .new_message"- Returns:
- SelenideElement
- See Also:
Locates the first element matching given CSS selector ATTENTION! This method doesn't start any search yet!
-
$
public static SelenideElement $(java.lang.String cssSelector, int index)
Locates the Nth element matching given criteria ATTENTION! This method doesn't start any search yet!- Parameters:
cssSelector- any CSS selector like "input[name='first_name']" or "#messages .new_message"index- 0..N- Returns:
- SelenideElement
-
$
@Deprecated public 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)- Parameters:
parent- the WebElement to search elements incssSelector- any CSS selector like "input[name='first_name']" or "#messages .new_message"index- 0..N- Returns:
- SelenideElement
- See Also:
Locates the Nth element matching given criteria ATTENTION! This method doesn't start any search yet!
-
$
@Deprecated public 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)- Parameters:
parent- the WebElement to search elements inseleniumSelector- any Selenium selector like By.id(), By.name() etc.- Returns:
- SelenideElement
- See Also:
Locates the first element matching given criteria ATTENTION! This method doesn't start any search yet!
-
$
@Deprecated public 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)- Parameters:
parent- the WebElement to search elements inseleniumSelector- any Selenium selector like By.id(), By.name() etc.index- 0..N- Returns:
- SelenideElement
- See Also:
Locates the Nth element matching given criteria ATTENTION! This method doesn't start any search yet!
-
$$
public static ElementsCollection $$(java.util.Collection<? extends org.openqa.selenium.WebElement> elements)
Initialize collection with Elements
-
$$
public static ElementsCollection $$(java.lang.String cssSelector)
Locates all elements matching given CSS selector. 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.- Parameters:
cssSelector- any CSS selector like "input[name='first_name']" or "#messages .new_message"- Returns:
- empty list if element was no found
-
$$x
public static ElementsCollection $$x(java.lang.String xpathExpression)
Locates all elements matching given XPATH expression. 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.- Parameters:
xpathExpression- any XPATH expression //*[@id='value'] //E[contains(@A, 'value')]- Returns:
- ElementsCollection which locates elements via XPath
-
$$
public static ElementsCollection $$(org.openqa.selenium.By seleniumSelector)
Locates all elements matching given CSS selector. 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.- Parameters:
seleniumSelector- any Selenium selector like By.id(), By.name() etc.- Returns:
- empty list if element was no found
-
$$
@Deprecated public 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)- Parameters:
parent- the WebElement to search elements incssSelector- any CSS selector like "input[name='first_name']" or "#messages .new_message"- Returns:
- empty list if element was no found
- See Also:
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 public 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)
-
element
public static SelenideElement element(org.openqa.selenium.WebElement webElement)
Wrap standard Selenium WebElement into SelenideElement to use additional methods like shouldHave(), selectOption() etc.- Parameters:
webElement- standard Selenium WebElement- Returns:
- given WebElement wrapped into SelenideElement
-
element
public static SelenideElement element(java.lang.String cssSelector)
Locates the first element matching given CSS selector ATTENTION! This method doesn't start any search yet!- Parameters:
cssSelector- any CSS selector like "input[name='first_name']" or "#messages .new_message"- Returns:
- SelenideElement
-
element
public 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!- Parameters:
seleniumSelector- any Selenium selector like By.id(), By.name() etc.- Returns:
- SelenideElement
-
element
public 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!- Parameters:
seleniumSelector- any Selenium selector like By.id(), By.name() etc.index- 0..N- Returns:
- SelenideElement
-
element
public 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!- Parameters:
cssSelector- any CSS selector like "input[name='first_name']" or "#messages .new_message"index- 0..N- Returns:
- SelenideElement
-
elements
public 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.- Parameters:
elements- standard Selenium WebElement collection- Returns:
- given WebElement collection wrapped into SelenideElement collection
-
elements
public static ElementsCollection elements(java.lang.String cssSelector)
Locates all elements matching given CSS selector. 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.- Parameters:
cssSelector- any CSS selector like "input[name='first_name']" or "#messages .new_message"- Returns:
- empty list if element was no found
-
elements
public static ElementsCollection elements(org.openqa.selenium.By seleniumSelector)
Locates all elements matching given CSS selector. 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.- Parameters:
seleniumSelector- any Selenium selector like By.id(), By.name() etc.- Returns:
- empty list if element was no found
-
getElement
@Deprecated public 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!- Parameters:
criteria- instance of By: By.id(), By.className() etc.- Returns:
- SelenideElement
-
getElement
@Deprecated public 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!- Parameters:
criteria- instance of By: By.id(), By.className() etc.index- 0..N- Returns:
- SelenideElement
-
getElements
@Deprecated public 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!- Parameters:
criteria- instance of By: By.id(), By.className() etc.- Returns:
- empty list if element was no found
-
executeJavaScript
public static <T> T executeJavaScript(java.lang.String jsCode, java.lang.Object... arguments)- See Also:
JavascriptExecutor.executeScript(java.lang.String, java.lang.Object...)
-
executeAsyncJavaScript
public static <T> T executeAsyncJavaScript(java.lang.String jsCode, java.lang.Object... arguments)- See Also:
JavascriptExecutor.executeAsyncScript(java.lang.String, java.lang.Object...)
-
getSelectedRadio
public static SelenideElement getSelectedRadio(org.openqa.selenium.By radioField)
Returns selected element in radio group- Returns:
- null if nothing selected
-
confirm
public static java.lang.String confirm()
Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'alert' or 'confirm').- Returns:
- actual dialog text
-
confirm
public static java.lang.String confirm(java.lang.String expectedDialogText)
Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'alert' or 'confirm').- Parameters:
expectedDialogText- if not null, check that confirmation dialog displays this message (case-sensitive)- Returns:
- actual dialog text
- Throws:
DialogTextMismatch- if confirmation message differs from expected message
-
prompt
public static java.lang.String prompt()
Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'prompt').- Returns:
- actual dialog text
-
prompt
public static java.lang.String prompt(java.lang.String inputText)
Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'prompt').- Parameters:
inputText- if not null, sets value in prompt dialog input- Returns:
- actual dialog text
-
prompt
public static java.lang.String prompt(java.lang.String expectedDialogText, java.lang.String inputText)Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'prompt').- Parameters:
expectedDialogText- if not null, check that confirmation dialog displays this message (case-sensitive)inputText- if not null, sets value in prompt dialog input- Returns:
- actual dialog text
- Throws:
DialogTextMismatch- if confirmation message differs from expected message
-
dismiss
public static java.lang.String dismiss()
Dismiss (click "No" or "Cancel") in the confirmation dialog (javascript 'alert' or 'confirm').- Returns:
- actual dialog text
-
dismiss
public static java.lang.String dismiss(java.lang.String expectedDialogText)
Dismiss (click "No" or "Cancel") in the confirmation dialog (javascript 'alert' or 'confirm').- Parameters:
expectedDialogText- if not null, check that confirmation dialog displays this message (case-sensitive)- Returns:
- actual dialog text
- Throws:
DialogTextMismatch- if confirmation message differs from expected message
-
switchTo
public static SelenideTargetLocator switchTo()
Switch to window/tab/frame/parentFrame/innerFrame/alert. Allows switching to window by title, index, name etc. Similar to org.openqa.selenium.WebDriver#switchTo(), but all methods wait until frame/window/alert appears if it's not visible yet (like other Selenide methods).- Returns:
- SelenideTargetLocator
-
getFocusedElement
public static org.openqa.selenium.WebElement getFocusedElement()
- Returns:
- WebElement, not SelenideElement! which has focus on it
-
page
public static <PageObjectClass> PageObjectClass page(java.lang.Class<PageObjectClass> pageObjectClass)
Create a Page Object instance
-
page
public static <PageObjectClass,T extends PageObjectClass> PageObjectClass page(T pageObject)
Initialize a given Page Object instance
-
Wait
public static SelenideWait Wait()
Create a org.openqa.selenium.support.ui.FluentWait instance with Selenide timeout/polling. Sample usage:Wait().until(invisibilityOfElementLocated(By.id("magic-id")));- Returns:
- instance of org.openqa.selenium.support.ui.FluentWait
-
actions
public static org.openqa.selenium.interactions.Actions actions()
With this method you can use Selenium Actions like described in the AdvancedUserInteractions page.actions() .sendKeys($(By.name("rememberMe")), "John") .click($(#rememberMe")) .click($(byText("Login"))) .build() .perform();
-
zoom
public static void zoom(double factor)
Zoom current page (in or out).- Parameters:
factor- e.g. 1.1 or 2.0 or 0.5
-
getWebDriverLogs
public 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)
-
getWebDriverLogs
public 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. messages) you can use:
for(String logEntry : getWebDriverLogs(LogType.BROWSER, Level.ALL)) { Reporter.log(logEntry + "<br>"); }
Be aware that currently "manage().logs()" is in the Beta stage, but it is beta-then-nothing :)
List of the unsupported browsers and issues:
http://bit.ly/RZcmrM
http://bit.ly/1nZTaqu- Parameters:
logType- WebDriver supported log typeslogLevel- logging level that will be used to control logging output- Returns:
- list of log entries
- See Also:
LogType,Level
-
clearBrowserCookies
public static void clearBrowserCookies()
Clear browser cookies. It can be useful e.g. if you are trying to avoid restarting browser between tests
-
clearBrowserLocalStorage
public static void clearBrowserLocalStorage()
Clear browser local storage. In case if you need to be sure that browser's localStorage is empty
-
getUserAgent
public static java.lang.String getUserAgent()
Get current user agent from browser session- Returns:
- browser user agent
-
atBottom
public 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.
-
download
public static java.io.File download(java.lang.String url) throws java.io.IOExceptionDownload file using a direct link. This method download file like it would be done in currently opened browser: it adds all cookies and "User-Agent" header to the downloading request. Download fails if default timeout (Configuration.timeout) is exceeded- Parameters:
url- either relative or absolute url- Returns:
- downloaded File in folder `Configuration.reportsFolder`
- Throws:
java.io.IOException- if failed to download file
-
download
public static java.io.File download(java.lang.String url, long timeoutMs) throws java.io.IOExceptionDownload file using a direct link. This method download file like it would be done in currently opened browser: it adds all cookies and "User-Agent" header to the downloading request. Download fails if specified timeout is exceeded- Parameters:
url- either relative or absolute urltimeoutMs- specific timeout in ms- Returns:
- downloaded File in folder `Configuration.reportsFolder`
- Throws:
java.io.IOException- if failed to download file
-
-