Class Selenide

java.lang.Object
com.codeborne.selenide.Selenide

@ParametersAreNonnullByDefault public class Selenide extends Object
The main starting point of Selenide.

You start with methods open(String) for opening the tested application page and $(String) for searching web elements.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.codeborne.selenide.SelenideElement
    $(String cssSelector)
    Locates the first element matching given CSS selector (lazy evaluation)
    static com.codeborne.selenide.SelenideElement
    $(String cssSelector, int index)
    Locates the Nth element matching given criteria (lazy evaluation)
    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
    $(org.openqa.selenium.WebElement webElement)
    Wrap standard Selenium WebElement into SelenideElement to use additional methods like SelenideElement.shouldHave(Condition...), SelenideElement.selectOption(String, String...) etc.
    static com.codeborne.selenide.ElementsCollection
    $$(String cssSelector)
    Locates all elements matching given CSS selector (lazy evaluation).
    static com.codeborne.selenide.ElementsCollection
    $$(Collection<? extends org.openqa.selenium.WebElement> elements)
    Initialize collection with Elements
    static com.codeborne.selenide.ElementsCollection
    $$(org.openqa.selenium.By seleniumSelector)
    Locates all elements matching given CSS selector.
    static com.codeborne.selenide.ElementsCollection
    $$x(String xpathExpression)
    Locates all elements matching given XPATH expression (lazy evaluation)
    static com.codeborne.selenide.SelenideElement
    $x(String xpathExpression)
    Locates the first element matching given XPATH expression (lazy evaluation)
    static org.openqa.selenium.interactions.Actions
    With this method you can use Selenium Actions like described in the AdvancedUserInteractions page.
    static boolean
    Return true if bottom of the page is reached
    static void
    Navigate browser back to previous page
    static void
    Clear browser cookies.
    static void
    Clear browser local storage.
    static com.codeborne.selenide.Clipboard
    Provide access to system clipboard, allows get and set String content.
    static void
    Close the browser if it's open.
    static void
    Close the current window, quitting the browser if it's the last window currently open.
    static String
    Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'alert' or 'confirm').
    static String
    confirm(com.codeborne.selenide.ModalOptions options)
    Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'alert' or 'confirm').
    static String
    confirm(String expectedDialogText)
    Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'alert' or 'confirm').
    static String
    Copy selected text or empty string if no text is selected to clipboard.
    static String
    Dismiss (click "No" or "Cancel") in the confirmation dialog (javascript 'alert' or 'confirm').
    static String
    dismiss(com.codeborne.selenide.ModalOptions options)
    Dismiss (click "No" or "Cancel") in the confirmation dialog (javascript 'alert' or 'confirm').
    static String
    dismiss(String expectedDialogText)
    Dismiss (click "No" or "Cancel") in the confirmation dialog (javascript 'alert' or 'confirm').
    static File
    NB! URL must be properly encoded.
    static File
    download(String url, long timeoutMs)
    Download file using a direct link.
    static File
     
    static File
    download(URI url, long timeoutMs)
     
    static com.codeborne.selenide.SelenideElement
    element(String cssSelector)
    Locates the first element matching given CSS selector
    static com.codeborne.selenide.SelenideElement
    element(String cssSelector, int index)
    Locates the Nth element matching given criteria
    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(org.openqa.selenium.WebElement webElement)
    Wrap standard Selenium WebElement into SelenideElement to use additional methods like SelenideElement.shouldHave(Condition...), SelenideElement.selectOption(String, String...) etc.
    static com.codeborne.selenide.ElementsCollection
    elements(String cssSelector)
    Locates all elements matching given CSS selector.
    static com.codeborne.selenide.ElementsCollection
    elements(Collection<? extends org.openqa.selenium.WebElement> elements)
    Wrap standard Selenium WebElement collection into SelenideElement collection to use additional methods like SelenideElement.shouldHave(Condition...) etc.
    static com.codeborne.selenide.ElementsCollection
    elements(org.openqa.selenium.By seleniumSelector)
    Locates all elements matching given CSS selector.
    static <T> T
    executeAsyncJavaScript(String jsCode, Object... arguments)
     
    static <T> T
    executeJavaScript(String jsCode, Object... arguments)
     
    static void
    Navigate browser forward to next page
    static com.codeborne.selenide.SelenideElement
     
    static com.codeborne.selenide.SelenideElement
    getSelectedRadio(org.openqa.selenium.By radioField)
    Returns selected element in radio group
    static String
    Returns selected text or empty string if no text is selected.
    static String
    Get current user agent from browser session
    static List<String>
    static List<String>
    getWebDriverLogs(String logType, 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 a new browser (with the same settings as the default browser), and run given code block in this browser.
    static com.codeborne.selenide.LocalStorage
    Access browser's local storage.
    static void
    Open an empty browser (without opening any pages).
    static void
    open(String relativeOrAbsoluteUrl)
    The main starting point in your tests.
    static void
    open(String relativeOrAbsoluteUrl, com.codeborne.selenide.AuthenticationType authenticationType, com.codeborne.selenide.Credentials credentials)
    The main starting point in your tests.
    static void
    open(String relativeOrAbsoluteUrl, com.codeborne.selenide.AuthenticationType authenticationType, String login, String password)
    Deprecated.
    AFAIK "login+password" combination is only used in BASIC authentication.
    static <PageObjectClass>
    PageObjectClass
    open(String relativeOrAbsoluteUrl, Class<PageObjectClass> pageObjectClassClass)
    Open a web page and create PageObject for it.
    static void
    open(String relativeOrAbsoluteUrl, String domain, String login, String password)
    The main starting point in your tests.
    static <PageObjectClass>
    PageObjectClass
    open(String relativeOrAbsoluteUrl, String domain, String login, String password, Class<PageObjectClass> pageObjectClassClass)
    Open a web page using Basic Auth credentials and create PageObject for it.
    static void
    open(URL absoluteUrl)
     
    static <PageObjectClass>
    PageObjectClass
    open(URL absoluteUrl, Class<PageObjectClass> pageObjectClassClass)
    Open a web page and create PageObject for it.
    static void
    open(URL absoluteUrl, String domain, String login, String password)
     
    static <PageObjectClass>
    PageObjectClass
    open(URL absoluteUrl, String domain, String login, String password, Class<PageObjectClass> pageObjectClassClass)
    Open a web page using Basic Auth credentials and create PageObject for it.
    static <PageObjectClass>
    PageObjectClass
    page(Class<PageObjectClass> pageObjectClass)
    Create a Page Object instance
    static <PageObjectClass>
    PageObjectClass
    page(PageObjectClass... reified)
    Create a Page Object instance
    static <PageObjectClass, T extends PageObjectClass>
    PageObjectClass
    page(T pageObject)
    Initialize a given Page Object instance
    static String
    Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'prompt').
    static String
    prompt(com.codeborne.selenide.ModalOptions options, String inputText)
    Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'prompt').
    static String
    prompt(String inputText)
    Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'prompt').
    static String
    prompt(String expectedDialogText, String inputText)
    Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'prompt').
    static void
    Reload current page
    static String
    screenshot(String fileName)
    Take the screenshot of current page and save to file fileName.html and fileName.png
    static <T> T
    screenshot(org.openqa.selenium.OutputType<T> outputType)
    Take the screenshot of current page and return it.
    static org.openqa.selenium.remote.SessionId
    Get current browser session Id
    static com.codeborne.selenide.SessionStorage
    Access browser's session storage.
    static void
    sleep(long milliseconds)
    Not recommended.
    static com.codeborne.selenide.SelenideTargetLocator
    Switch to window/tab/frame/parentFrame/innerFrame/alert.
    static String
     
    static void
    Update the hash of the window location.
    static void
    using(org.openqa.selenium.WebDriver webDriver, com.codeborne.selenide.proxy.SelenideProxyServer proxy, Runnable lambda)
     
    static void
    using(org.openqa.selenium.WebDriver webDriver, Runnable lambda)
     
    static com.codeborne.selenide.SelenideWait
    Create a org.openqa.selenium.support.ui.FluentWait instance with Selenide timeout/polling.
    static com.codeborne.selenide.Conditional<org.openqa.selenium.WebDriver>
     
    static void
    zoom(double factor)
    Zoom current page (in or out).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Selenide

      public Selenide()
  • Method Details

    • open

      public static void open(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(URL absoluteUrl)
      See Also:
    • open

      public static void open(String relativeOrAbsoluteUrl, String domain, String login, 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

      Parameters:
      domain - Name of domain to apply Basic Auth. 1. If empty, Basic Auth will be applied to all domains. 2. If non-empty, Basic Auth will be applied only to URLs containing this domain. 2.1. May contain multiple domain names (delimited by "," or "|").
    • open

      @Deprecated public static void open(String relativeOrAbsoluteUrl, com.codeborne.selenide.AuthenticationType authenticationType, String login, String password)
      Deprecated.
      AFAIK "login+password" combination is only used in BASIC authentication. If you need basic auth, use open(String, AuthenticationType, Credentials) with BasicAuthCredentials parameter.
      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.proxyEnabled == true

      See Also:
    • open

      public static void open(String relativeOrAbsoluteUrl, com.codeborne.selenide.AuthenticationType authenticationType, com.codeborne.selenide.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.proxyEnabled == true

      See Also:
    • open

      public static void open(URL absoluteUrl, String domain, String login, String password)
      See Also:
    • open

      public static void open()
      Open an empty browser (without opening any pages). E.g. useful for starting mobile applications in Appium.
    • webdriver

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.Conditional<org.openqa.selenium.WebDriver> webdriver()
      Since:
      5.23.0
    • using

      public static void using(org.openqa.selenium.WebDriver webDriver, Runnable lambda)
    • using

      public static void using(org.openqa.selenium.WebDriver webDriver, com.codeborne.selenide.proxy.SelenideProxyServer proxy, Runnable lambda)
    • inNewBrowser

      public static void inNewBrowser(Runnable lambda)
      Open a new browser (with the same settings as the default browser), and run given code block in this browser.

      In the end, the browser will be closed.

      Since:
      6.13.0
    • updateHash

      public static void updateHash(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

      @CheckReturnValue @Nonnull public static <PageObjectClass> PageObjectClass open(String relativeOrAbsoluteUrl, Class<PageObjectClass> pageObjectClassClass)
      Open a web page and create PageObject for it.
      Returns:
      PageObject of given class
    • open

      @CheckReturnValue @Nonnull public static <PageObjectClass> PageObjectClass open(URL absoluteUrl, Class<PageObjectClass> pageObjectClassClass)
      Open a web page and create PageObject for it.
      Returns:
      PageObject of given class
    • open

      @CheckReturnValue @Nonnull public static <PageObjectClass> PageObjectClass open(String relativeOrAbsoluteUrl, String domain, String login, String password, Class<PageObjectClass> pageObjectClassClass)
      Open a web page using Basic Auth credentials and create PageObject for it.
      Returns:
      PageObject of given class
    • open

      @CheckReturnValue @Nonnull public static <PageObjectClass> PageObjectClass open(URL absoluteUrl, String domain, String login, String password, 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()
    • 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

      @CheckReturnValue @Nullable public static 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.

      Implementation detail: method 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.

      Parameters:
      milliseconds - Time to sleep in milliseconds
    • screenshot

      @CheckReturnValue @Nullable public static String screenshot(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
    • screenshot

      @CheckReturnValue @Nullable public static <T> T screenshot(org.openqa.selenium.OutputType<T> outputType)
      Take the screenshot of current page and return it.
      Parameters:
      outputType - type of the returned screenshot
      Returns:
      The screenshot (as bytes, base64 or temporary file) or null if webdriver does not support taking screenshots.
    • $

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.SelenideElement $(org.openqa.selenium.WebElement webElement)
      Wrap standard Selenium WebElement into SelenideElement to use additional methods like SelenideElement.shouldHave(Condition...), SelenideElement.selectOption(String, String...) etc.
      Parameters:
      webElement - standard Selenium WebElement
      Returns:
      given WebElement wrapped into SelenideElement
    • $

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.SelenideElement $(String cssSelector)
      Locates the first element matching given CSS selector (lazy evaluation)
      Parameters:
      cssSelector - any CSS selector like "input[name='first_name']" or "#messages .new_message"
      Returns:
      SelenideElement
      See Also:
    • $x

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.SelenideElement $x(String xpathExpression)
      Locates the first element matching given XPATH expression (lazy evaluation)
      Parameters:
      xpathExpression - any XPATH expression //*[@id='value'] //E[contains(@A, 'value')]
      Returns:
      SelenideElement which locates elements via XPath
      See Also:
    • $

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.SelenideElement $(org.openqa.selenium.By seleniumSelector)
      Locates the first element matching given CSS selector (lazy evaluation)
      Parameters:
      seleniumSelector - any Selenium selector like By.id(), By.name() etc.
      Returns:
      SelenideElement
      See Also:
    • $

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.SelenideElement $(org.openqa.selenium.By seleniumSelector, int index)
      See Also:
    • $

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.SelenideElement $(String cssSelector, int index)
      Locates the Nth element matching given criteria (lazy evaluation)
      Parameters:
      cssSelector - any CSS selector like "input[name='first_name']" or "#messages .new_message"
      index - 0..N
      Returns:
      SelenideElement
      See Also:
    • $$

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.ElementsCollection $$(Collection<? extends org.openqa.selenium.WebElement> elements)
      Initialize collection with Elements
    • $$

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.ElementsCollection $$(String cssSelector)
      Locates all elements matching given CSS selector (lazy evaluation).

      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
      See Also:
    • $$x

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.ElementsCollection $$x(String xpathExpression)
      Locates all elements matching given XPATH expression (lazy evaluation)

      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
      See Also:
    • $$

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.ElementsCollection $$(org.openqa.selenium.By seleniumSelector)
      Locates all elements matching given CSS selector.

      Method 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
      See Also:
    • element

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.SelenideElement element(org.openqa.selenium.WebElement webElement)
      Wrap standard Selenium WebElement into SelenideElement to use additional methods like SelenideElement.shouldHave(Condition...), SelenideElement.selectOption(String, String...) etc.
      Parameters:
      webElement - standard Selenium WebElement
      Returns:
      given WebElement wrapped into SelenideElement
    • element

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.SelenideElement element(String cssSelector)
      Locates the first element matching given CSS selector
      Parameters:
      cssSelector - any CSS selector like "input[name='first_name']" or "#messages .new_message"
      Returns:
      SelenideElement
      See Also:
    • element

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.SelenideElement element(org.openqa.selenium.By seleniumSelector)
      Locates the first element matching given CSS selector
      Parameters:
      seleniumSelector - any Selenium selector like By.id(String), By.name(String) etc.
      Returns:
      SelenideElement
      See Also:
    • element

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.SelenideElement element(org.openqa.selenium.By seleniumSelector, int index)
      Locates the Nth element matching given criteria
      Parameters:
      seleniumSelector - any Selenium selector like By.id(String), By.name(String) etc.
      index - 0..N
      Returns:
      SelenideElement
      See Also:
    • element

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.SelenideElement element(String cssSelector, int index)
      Locates the Nth element matching given criteria
      Parameters:
      cssSelector - any CSS selector like "input[name='first_name']" or "#messages .new_message"
      index - 0..N
      Returns:
      SelenideElement
      See Also:
    • elements

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.ElementsCollection elements(Collection<? extends org.openqa.selenium.WebElement> elements)
      Wrap standard Selenium WebElement collection into SelenideElement collection to use additional methods like SelenideElement.shouldHave(Condition...) etc.
      Parameters:
      elements - standard Selenium WebElement collection
      Returns:
      given WebElement collection wrapped into SelenideElement collection
    • elements

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.ElementsCollection elements(String cssSelector)
      Locates all elements matching given CSS selector.

      Method 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 WebElement.sendKeys(CharSequence...), WebElement.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
      See Also:
    • elements

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.ElementsCollection elements(org.openqa.selenium.By seleniumSelector)
      Locates all elements matching given CSS selector.

      Method 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 WebElement.sendKeys(CharSequence...), WebElement.click() etc. on it.

      Parameters:
      seleniumSelector - any Selenium selector like By.id(), By.name() etc.
      Returns:
      empty list if element was no found
      See Also:
    • executeJavaScript

      @Nullable public static <T> T executeJavaScript(String jsCode, Object... arguments)
      See Also:
      • JavascriptExecutor.executeScript(String, java.lang.Object...)
    • executeAsyncJavaScript

      @Nullable public static <T> T executeAsyncJavaScript(String jsCode, Object... arguments)
      See Also:
      • JavascriptExecutor.executeAsyncScript(String, java.lang.Object...)
    • getSelectedRadio

      @CheckReturnValue @Nullable public static com.codeborne.selenide.SelenideElement getSelectedRadio(org.openqa.selenium.By radioField)
      Returns selected element in radio group
      Returns:
      null if nothing selected
    • confirm

      @Nullable public static String confirm()
      Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'alert' or 'confirm').
      Returns:
      actual dialog text
    • confirm

      @Nullable public static String confirm(@Nullable 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:
      com.codeborne.selenide.ex.DialogTextMismatch - if confirmation message differs from expected message
    • confirm

      @Nullable public static String confirm(com.codeborne.selenide.ModalOptions options)
      Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'alert' or 'confirm').
      Parameters:
      options - parameters: timeout, expected texts etc.
      Returns:
      actual dialog text
      Throws:
      com.codeborne.selenide.ex.DialogTextMismatch - if confirmation message differs from expected message
      Since:
      6.6.0
    • prompt

      @Nullable public static String prompt()
      Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'prompt').
      Returns:
      actual dialog text
    • prompt

      @Nullable public static String prompt(@Nullable 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

      @Nullable public static String prompt(@Nullable String expectedDialogText, @Nullable 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:
      com.codeborne.selenide.ex.DialogTextMismatch - if confirmation message differs from expected message
    • prompt

      @Nullable public static String prompt(com.codeborne.selenide.ModalOptions options, @Nullable String inputText)
      Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'prompt').
      Parameters:
      options - parameters: timeout, expected texts etc.
      inputText - if not null, sets value in prompt dialog input
      Returns:
      actual dialog text
      Throws:
      com.codeborne.selenide.ex.DialogTextMismatch - if confirmation message differs from expected message
      Since:
      6.6.0
    • dismiss

      @Nullable public static String dismiss()
      Dismiss (click "No" or "Cancel") in the confirmation dialog (javascript 'alert' or 'confirm').
      Returns:
      actual dialog text
    • dismiss

      @Nullable public static String dismiss(@Nullable 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:
      com.codeborne.selenide.ex.DialogTextMismatch - if confirmation message differs from expected message
    • dismiss

      @Nullable public static String dismiss(com.codeborne.selenide.ModalOptions options)
      Dismiss (click "No" or "Cancel") in the confirmation dialog (javascript 'alert' or 'confirm').
      Parameters:
      options - if not null, check that confirmation dialog displays this message (case-sensitive)
      Returns:
      actual dialog text
      Throws:
      com.codeborne.selenide.ex.DialogTextMismatch - if confirmation message differs from expected message
      Since:
      6.6.0
    • switchTo

      @Nonnull @CheckReturnValue public static com.codeborne.selenide.SelenideTargetLocator switchTo()
      Switch to window/tab/frame/parentFrame/innerFrame/alert. Allows switching to window by title, index, name etc.

      Similar to WebDriver.switchTo(), but all methods wait until frame/window/alert appears if it's not visible yet (like other Selenide methods).

      Returns:
      SelenideTargetLocator
    • getFocusedElement

      @CheckReturnValue public static com.codeborne.selenide.SelenideElement getFocusedElement()
      Returns:
      the element that currently is focused, or null if none of elements if focused
    • getSelectedText

      @CheckReturnValue @Nonnull public static String getSelectedText()
      Returns selected text or empty string if no text is selected.
      Returns:
      selected text
      Since:
      6.11.0
    • copy

      public static String copy()
      Copy selected text or empty string if no text is selected to clipboard.
      Returns:
      the copied text
      Since:
      6.11.0
      See Also:
    • page

      @CheckReturnValue @Nonnull public static <PageObjectClass> PageObjectClass page(Class<PageObjectClass> pageObjectClass)
      Create a Page Object instance
    • page

      @CheckReturnValue @Nonnull public static <PageObjectClass> PageObjectClass page(PageObjectClass... reified)
      Create a Page Object instance
      Parameters:
      reified - Don't pass any values here. It's Java Magic :)
      Since:
      6.8.0
    • page

      @CheckReturnValue @Nonnull public static <PageObjectClass, T extends PageObjectClass> PageObjectClass page(T pageObject)
      Initialize a given Page Object instance
    • Wait

      @CheckReturnValue @Nonnull public static com.codeborne.selenide.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

      @CheckReturnValue @Nonnull 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

      @CheckReturnValue @Nonnull public static List<String> getWebDriverLogs(String logType)
    • getWebDriverLogs

      @Nonnull @CheckReturnValue public static List<String> getWebDriverLogs(String logType, 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 types
      logLevel - logging level that will be used to control logging output
      Returns:
      list of log entries
      See Also:
    • 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

      @Nonnull @CheckReturnValue public static String getUserAgent()
      Get current user agent from browser session
      Returns:
      browser user agent
    • atBottom

      @CheckReturnValue 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

      @Nonnull @CheckReturnValue public static File download(String url) throws IOException, URISyntaxException
      NB! URL must be properly encoded. E.g. instead of "/files/ж.txt", it should be "/files/%D0%B6.txt"
      Throws:
      IOException
      URISyntaxException
      See Also:
    • download

      @Nonnull @CheckReturnValue public static File download(URI url) throws IOException
      Throws:
      IOException
      See Also:
    • download

      @Nonnull @CheckReturnValue public static File download(URI url, long timeoutMs) throws IOException
      Throws:
      IOException
      See Also:
    • download

      @Nonnull @CheckReturnValue public static File download(String url, long timeoutMs) throws IOException, URISyntaxException
      Download 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 url NB! URL must be properly encoded. E.g. instead of "/files/ж.txt", it should be "/files/%D0%B6.txt"
      timeoutMs - specific timeout in ms
      Returns:
      downloaded File in folder `Configuration.reportsFolder`
      Throws:
      IOException - if failed to download file
      URISyntaxException - if given url has invalid syntax
    • localStorage

      @Nonnull @CheckReturnValue public static com.codeborne.selenide.LocalStorage localStorage()
      Access browser's local storage. Allows setting, getting, removing items as well as getting the size and clear the storage.
      Returns:
      LocalStorage
      Since:
      5.15.0
    • sessionStorage

      @Nonnull @CheckReturnValue public static com.codeborne.selenide.SessionStorage sessionStorage()
      Access browser's session storage. Allows setting, getting, removing items as well as getting the size, check for contains item and clear the storage.
      Returns:
      sessionStorage
      Since:
      5.18.1
    • clipboard

      @Nonnull @CheckReturnValue public static com.codeborne.selenide.Clipboard clipboard()
      Provide access to system clipboard, allows get and set String content. Default implementation acts via Toolkit and supports only local runs.

      Remote runs support can be implemented via plugins. Plugin for Selenoid supports clipboard since v1.1.0.

      Returns:
      Clipboard
      Since:
      5.20.0
      See Also:
      • selenide-selenoid

        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.

    • sessionId

      @Nonnull @CheckReturnValue public static org.openqa.selenium.remote.SessionId sessionId()
      Get current browser session Id
      Returns:
      SessionId