@ParametersAreNonnullByDefault
public class Selenide
extends java.lang.Object
You start with methods 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 com.codeborne.selenide.SelenideElement |
$(org.openqa.selenium.By seleniumSelector)
Locates the first element matching given CSS selector (lazy evaluation)
|
static com.codeborne.selenide.SelenideElement |
$(org.openqa.selenium.By seleniumSelector,
int index) |
static com.codeborne.selenide.SelenideElement |
$(java.lang.String cssSelector)
Locates the first element matching given CSS selector (lazy evaluation)
|
static com.codeborne.selenide.SelenideElement |
$(java.lang.String cssSelector,
int index)
Locates the Nth element matching given criteria (lazy evaluation)
|
static com.codeborne.selenide.SelenideElement |
$(org.openqa.selenium.WebElement webElement)
Wrap standard Selenium WebElement into SelenideElement
to use additional methods like shouldHave(), selectOption() etc.
|
static com.codeborne.selenide.ElementsCollection |
$$(org.openqa.selenium.By seleniumSelector)
Locates all elements matching given CSS selector.
|
static com.codeborne.selenide.ElementsCollection |
$$(java.util.Collection<? extends org.openqa.selenium.WebElement> elements)
Initialize collection with Elements
|
static com.codeborne.selenide.ElementsCollection |
$$(java.lang.String cssSelector)
Locates all elements matching given CSS selector (lazy evaluation).
|
static com.codeborne.selenide.ElementsCollection |
$$x(java.lang.String xpathExpression)
Locates all elements matching given XPATH expression (lazy evaluation)
|
static com.codeborne.selenide.SelenideElement |
$x(java.lang.String xpathExpression)
Locates the first element matching given XPATH expression (lazy evaluation)
|
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
|
static void |
back()
Navigate browser back to previous page
|
static void |
clearBrowserCookies()
Clear browser cookies.
|
static void |
clearBrowserLocalStorage()
Clear browser local storage.
|
static com.codeborne.selenide.Clipboard |
clipboard()
Provide access to system clipboard, allows get and set String content.
|
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)
NB! URL must be properly encoded.
|
static java.io.File |
download(java.lang.String url,
long timeoutMs)
Download file using a direct link.
|
static java.io.File |
download(java.net.URI url) |
static java.io.File |
download(java.net.URI url,
long timeoutMs) |
static com.codeborne.selenide.SelenideElement |
element(org.openqa.selenium.By seleniumSelector)
Locates the first element matching given CSS selector
|
static com.codeborne.selenide.SelenideElement |
element(org.openqa.selenium.By seleniumSelector,
int index)
Locates the Nth element matching given criteria
|
static com.codeborne.selenide.SelenideElement |
element(java.lang.String cssSelector)
Locates the first element matching given CSS selector
|
static com.codeborne.selenide.SelenideElement |
element(java.lang.String cssSelector,
int index)
Locates the Nth element matching given criteria
|
static com.codeborne.selenide.SelenideElement |
element(org.openqa.selenium.WebElement webElement)
Wrap standard Selenium WebElement into SelenideElement
to use additional methods like shouldHave(), selectOption() etc.
|
static com.codeborne.selenide.ElementsCollection |
elements(org.openqa.selenium.By seleniumSelector)
Locates all elements matching given CSS selector.
|
static com.codeborne.selenide.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 com.codeborne.selenide.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 org.openqa.selenium.WebElement |
getFocusedElement() |
static com.codeborne.selenide.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 com.codeborne.selenide.LocalStorage |
localStorage()
Access browser's local storage.
|
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,
com.codeborne.selenide.AuthenticationType authenticationType,
com.codeborne.selenide.Credentials credentials)
The main starting point in your tests.
|
static void |
open(java.lang.String relativeOrAbsoluteUrl,
com.codeborne.selenide.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 <T> T |
screenshot(org.openqa.selenium.OutputType<T> outputType)
Take the screenshot of current page and return it.
|
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 org.openqa.selenium.remote.SessionId |
sessionId()
Get current browser session Id
|
static com.codeborne.selenide.SessionStorage |
sessionStorage()
Access browser's session storage.
|
static void |
sleep(long milliseconds)
Not recommended.
|
static com.codeborne.selenide.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 com.codeborne.selenide.SelenideWait |
Wait()
Create a org.openqa.selenium.support.ui.FluentWait instance with Selenide timeout/polling.
|
static com.codeborne.selenide.Conditional<org.openqa.selenium.WebDriver> |
webdriver() |
static void |
zoom(double factor)
Zoom current page (in or out).
|
public static void open(java.lang.String relativeOrAbsoluteUrl)
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.
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,
com.codeborne.selenide.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;
AuthenticationTypepublic static void open(java.lang.String relativeOrAbsoluteUrl,
com.codeborne.selenide.AuthenticationType authenticationType,
com.codeborne.selenide.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,
Credentialspublic 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()
@CheckReturnValue @Nonnull public static com.codeborne.selenide.Conditional<org.openqa.selenium.WebDriver> webdriver()
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".@CheckReturnValue
@Nonnull
public static <PageObjectClass> PageObjectClass open(java.lang.String relativeOrAbsoluteUrl,
java.lang.Class<PageObjectClass> pageObjectClassClass)
@CheckReturnValue
@Nonnull
public static <PageObjectClass> PageObjectClass open(java.net.URL absoluteUrl,
java.lang.Class<PageObjectClass> pageObjectClassClass)
@CheckReturnValue
@Nonnull
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)
@CheckReturnValue
@Nonnull
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()public static void refresh()
public static void back()
public static void forward()
@CheckReturnValue @Nullable public static java.lang.String title()
public static void sleep(long milliseconds)
Thread.sleep(long) is not guaranteed to
sleep exactly given number of milliseconds, it can awake earlier. That's why we need to use a
loop to guarantee the sleep duration.milliseconds - Time to sleep in milliseconds@CheckReturnValue @Nullable public static java.lang.String screenshot(java.lang.String fileName)
fileName - Name of file (without extension) to save HTML and PNG to@CheckReturnValue @Nullable public static <T> T screenshot(org.openqa.selenium.OutputType<T> outputType)
outputType - type of the returned screenshot@CheckReturnValue @Nonnull public static com.codeborne.selenide.SelenideElement $(org.openqa.selenium.WebElement webElement)
webElement - standard Selenium WebElement@CheckReturnValue @Nonnull public static com.codeborne.selenide.SelenideElement $(java.lang.String cssSelector)
cssSelector - any CSS selector like "input[name='first_name']" or "#messages .new_message"@CheckReturnValue @Nonnull public static com.codeborne.selenide.SelenideElement $x(java.lang.String xpathExpression)
xpathExpression - any XPATH expression //*[@id='value'] //E[contains(@A, 'value')]@CheckReturnValue @Nonnull public static com.codeborne.selenide.SelenideElement $(org.openqa.selenium.By seleniumSelector)
seleniumSelector - any Selenium selector like By.id(), By.name() etc.@CheckReturnValue
@Nonnull
public static com.codeborne.selenide.SelenideElement $(org.openqa.selenium.By seleniumSelector,
int index)
element(By, int)@CheckReturnValue
@Nonnull
public static com.codeborne.selenide.SelenideElement $(java.lang.String cssSelector,
int index)
cssSelector - any CSS selector like "input[name='first_name']" or "#messages .new_message"index - 0..N@CheckReturnValue @Nonnull public static com.codeborne.selenide.ElementsCollection $$(java.util.Collection<? extends org.openqa.selenium.WebElement> elements)
@CheckReturnValue @Nonnull public static com.codeborne.selenide.ElementsCollection $$(java.lang.String cssSelector)
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.
cssSelector - any CSS selector like "input[name='first_name']" or "#messages .new_message"@CheckReturnValue @Nonnull public static com.codeborne.selenide.ElementsCollection $$x(java.lang.String xpathExpression)
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.
xpathExpression - any XPATH expression //*[@id='value'] //E[contains(@A, 'value')]@CheckReturnValue @Nonnull public static com.codeborne.selenide.ElementsCollection $$(org.openqa.selenium.By seleniumSelector)
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.
seleniumSelector - any Selenium selector like By.id(), By.name() etc.@CheckReturnValue @Nonnull public static com.codeborne.selenide.SelenideElement element(org.openqa.selenium.WebElement webElement)
webElement - standard Selenium WebElement@CheckReturnValue @Nonnull public static com.codeborne.selenide.SelenideElement element(java.lang.String cssSelector)
cssSelector - any CSS selector like "input[name='first_name']" or "#messages .new_message"@CheckReturnValue @Nonnull public static com.codeborne.selenide.SelenideElement element(org.openqa.selenium.By seleniumSelector)
seleniumSelector - any Selenium selector like By.id(), By.name() etc.@CheckReturnValue
@Nonnull
public static com.codeborne.selenide.SelenideElement element(org.openqa.selenium.By seleniumSelector,
int index)
seleniumSelector - any Selenium selector like By.id(), By.name() etc.index - 0..N@CheckReturnValue
@Nonnull
public static com.codeborne.selenide.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 @Nonnull public static com.codeborne.selenide.ElementsCollection elements(java.util.Collection<? extends org.openqa.selenium.WebElement> elements)
elements - standard Selenium WebElement collection@CheckReturnValue @Nonnull public static com.codeborne.selenide.ElementsCollection elements(java.lang.String cssSelector)
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.
cssSelector - any CSS selector like "input[name='first_name']" or "#messages .new_message"@CheckReturnValue @Nonnull public static com.codeborne.selenide.ElementsCollection elements(org.openqa.selenium.By seleniumSelector)
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.
seleniumSelector - any Selenium selector like By.id(), By.name() etc.@Nullable
public static <T> T executeJavaScript(java.lang.String jsCode,
java.lang.Object... arguments)
JavascriptExecutor.executeScript(java.lang.String, java.lang.Object...)@Nullable
public static <T> T executeAsyncJavaScript(java.lang.String jsCode,
java.lang.Object... arguments)
JavascriptExecutor.executeAsyncScript(java.lang.String, java.lang.Object...)@CheckReturnValue @Nullable public static com.codeborne.selenide.SelenideElement getSelectedRadio(org.openqa.selenium.By radioField)
@Nullable public static java.lang.String confirm()
@Nullable
public static java.lang.String confirm(@Nullable
java.lang.String expectedDialogText)
expectedDialogText - if not null, check that confirmation dialog displays this message (case-sensitive)com.codeborne.selenide.ex.DialogTextMismatch - if confirmation message differs from expected message@Nullable public static java.lang.String prompt()
@Nullable
public static java.lang.String prompt(@Nullable
java.lang.String inputText)
inputText - if not null, sets value in prompt dialog input@Nullable
public static java.lang.String prompt(@Nullable
java.lang.String expectedDialogText,
@Nullable
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 inputcom.codeborne.selenide.ex.DialogTextMismatch - if confirmation message differs from expected message@Nullable public static java.lang.String dismiss()
@Nullable
public static java.lang.String dismiss(@Nullable
java.lang.String expectedDialogText)
expectedDialogText - if not null, check that confirmation dialog displays this message (case-sensitive)com.codeborne.selenide.ex.DialogTextMismatch - if confirmation message differs from expected message@Nonnull @CheckReturnValue public static com.codeborne.selenide.SelenideTargetLocator switchTo()
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).
@CheckReturnValue @Nullable public static org.openqa.selenium.WebElement getFocusedElement()
@CheckReturnValue @Nonnull public static <PageObjectClass> PageObjectClass page(java.lang.Class<PageObjectClass> pageObjectClass)
@CheckReturnValue @Nonnull public static <PageObjectClass,T extends PageObjectClass> PageObjectClass page(T pageObject)
@CheckReturnValue @Nonnull public static com.codeborne.selenide.SelenideWait Wait()
Sample usage:
Wait().until(invisibilityOfElementLocated(By.id("magic-id")));
@CheckReturnValue @Nonnull 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.5@CheckReturnValue @Nonnull public static java.util.List<java.lang.String> getWebDriverLogs(java.lang.String logType)
@Nonnull
@CheckReturnValue
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,
Levelpublic static void clearBrowserCookies()
It can be useful e.g. if you are trying to avoid restarting browser between tests
public static void clearBrowserLocalStorage()
In case if you need to be sure that browser's localStorage is empty
@Nonnull @CheckReturnValue public static java.lang.String getUserAgent()
@CheckReturnValue public static boolean atBottom()
Useful if you need to scroll down by x pixels unknown number of times.
@Nonnull
@CheckReturnValue
public static java.io.File download(java.lang.String url)
throws java.io.IOException,
java.net.URISyntaxException
java.io.IOExceptionjava.net.URISyntaxExceptionDownload fails if default timeout (Configuration.timeout) is exceeded@Nonnull
@CheckReturnValue
public static java.io.File download(java.net.URI url)
throws java.io.IOException
java.io.IOExceptiondownload(String)@Nonnull
@CheckReturnValue
public static java.io.File download(java.net.URI url,
long timeoutMs)
throws java.io.IOException
java.io.IOExceptiondownload(String, long)@Nonnull
@CheckReturnValue
public static java.io.File download(java.lang.String url,
long timeoutMs)
throws java.io.IOException,
java.net.URISyntaxException
Download fails if specified timeout is exceeded
url - either relative or absolute url
NB! URL must be properly encoded.
E.g. instead of "/files/ж.txt", it should be "/files/%D0%B6.txt"timeoutMs - specific timeout in msjava.io.IOException - if failed to download filejava.net.URISyntaxException - if given url has invalid syntax@Nonnull @CheckReturnValue public static com.codeborne.selenide.LocalStorage localStorage()
@Nonnull @CheckReturnValue public static com.codeborne.selenide.SessionStorage sessionStorage()
@Nonnull @CheckReturnValue public static com.codeborne.selenide.Clipboard clipboard()
Toolkit and supports only local runs.
Remote runs support can be implemented via plugins. Plugin for Selenoid will be released soon.
Pay attention that Clipboard is shared resource for instance where tests runs and keep in mind while developing test suite with multiple tests for clipboard.
@Nonnull @CheckReturnValue public static org.openqa.selenium.remote.SessionId sessionId()