Class Selenide


  • public class Selenide
    extends java.lang.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
      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 Elements
      static 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.Actions actions()
      With this method you can use Selenium Actions like described in the AdvancedUserInteractions page.
      static boolean atBottom()
      Return true if bottom of the page is reached Useful if you need to scroll down by x pixels unknown number of times.
      static void back()
      Navigate browser back to previous page
      static void clearBrowserCookies()
      Clear browser cookies.
      static void clearBrowserLocalStorage()
      Clear browser local storage.
      static void close()
      Deprecated.
      static void closeWebDriver()
      Close the browser if it's open.
      static void closeWindow()
      Close the current window, quitting the browser if it's the last window currently open.
      static java.lang.String confirm()
      Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'alert' or 'confirm').
      static java.lang.String confirm​(java.lang.String expectedDialogText)
      Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'alert' or 'confirm').
      static java.lang.String dismiss()
      Dismiss (click "No" or "Cancel") in the confirmation dialog (javascript 'alert' or 'confirm').
      static java.lang.String dismiss​(java.lang.String expectedDialogText)
      Dismiss (click "No" or "Cancel") in the confirmation dialog (javascript 'alert' or 'confirm').
      static java.io.File download​(java.lang.String url)
      Download file using a direct link.
      static java.io.File download​(java.lang.String url, long timeoutMs)
      Download file using a direct link.
      static SelenideElement element​(java.lang.String cssSelector)
      Locates the first element matching given CSS selector ATTENTION! This method doesn't start any search yet!
      static SelenideElement element​(java.lang.String cssSelector, int index)
      Locates the Nth element matching given criteria ATTENTION! This method doesn't start any search yet!
      static SelenideElement element​(org.openqa.selenium.By seleniumSelector)
      Locates the first element matching given CSS selector ATTENTION! This method doesn't start any search yet!
      static SelenideElement element​(org.openqa.selenium.By seleniumSelector, int index)
      Locates the Nth element matching given criteria ATTENTION! This method doesn't start any search yet!
      static SelenideElement element​(org.openqa.selenium.WebElement webElement)
      Wrap standard Selenium WebElement into SelenideElement to use additional methods like shouldHave(), selectOption() etc.
      static ElementsCollection elements​(java.lang.String cssSelector)
      Locates all elements matching given CSS selector.
      static ElementsCollection elements​(java.util.Collection<? extends org.openqa.selenium.WebElement> elements)
      Wrap standard Selenium WebElement collection into SelenideElement collection to use additional methods like shouldHave() etc.
      static ElementsCollection elements​(org.openqa.selenium.By seleniumSelector)
      Locates all elements matching given CSS selector.
      static <T> T executeJavaScript​(java.lang.String jsCode, java.lang.Object... arguments)  
      static void forward()
      Navigate browser forward to next page
      static SelenideElement getElement​(org.openqa.selenium.By criteria)
      Deprecated.
      please use element(criteria) which is the same (method will not be removed until 4.x or later) Locates the first element matching given criteria ATTENTION! This method doesn't start any search yet!
      static SelenideElement getElement​(org.openqa.selenium.By criteria, int index)
      Deprecated.
      please use element(criteria, index) which is the same (method will not be removed until 4.x or later) Locates the Nth element matching given criteria ATTENTION! This method doesn't start any search yet!
      static ElementsCollection getElements​(org.openqa.selenium.By criteria)
      Deprecated.
      please use elements(criteria) which is the same (method will not be removed until 4.x or later) Locates all elements matching given CSS selector ATTENTION! This method doesn't start any search yet!
      static org.openqa.selenium.WebElement getFocusedElement()  
      static SelenideElement getSelectedRadio​(org.openqa.selenium.By radioField)
      Returns selected element in radio group
      static java.lang.String getUserAgent()
      Get current user agent from browser session
      static java.util.List<java.lang.String> getWebDriverLogs​(java.lang.String logType)
      Same as com.codeborne.selenide.Selenide#getWebDriverLogs(java.lang.String, java.util.logging.Level)
      static java.util.List<java.lang.String> getWebDriverLogs​(java.lang.String logType, java.util.logging.Level logLevel)
      Getting and filtering of the WebDriver logs for specified LogType by specified logging level
      For example to get WebDriver Browser's console output (including JS info, warnings, errors, etc.
      static void open()
      Open an empty browser (without opening any pages).
      static void open​(java.lang.String relativeOrAbsoluteUrl)
      The main starting point in your tests.
      static void open​(java.lang.String relativeOrAbsoluteUrl, AuthenticationType authenticationType, Credentials credentials)
      The main starting point in your tests.
      static void open​(java.lang.String relativeOrAbsoluteUrl, AuthenticationType authenticationType, java.lang.String login, java.lang.String password)
      The main starting point in your tests.
      static <PageObjectClass>
      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>
      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>
      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>
      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>
      PageObjectClass
      page​(java.lang.Class<PageObjectClass> pageObjectClass)
      Create a Page Object instance
      static <PageObjectClass,​T extends PageObjectClass>
      PageObjectClass
      page​(T pageObject)
      Initialize a given Page Object instance
      static java.lang.String prompt()
      Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'prompt').
      static java.lang.String prompt​(java.lang.String inputText)
      Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'prompt').
      static java.lang.String prompt​(java.lang.String expectedDialogText, java.lang.String inputText)
      Accept (Click "Yes" or "Ok") in the confirmation dialog (javascript 'prompt').
      static void refresh()
      Reload current page
      static java.lang.String screenshot​(java.lang.String fileName)
      Take the screenshot of current page and save to file fileName.html and fileName.png
      static void sleep​(long milliseconds)
      Not recommended.
      static SelenideTargetLocator switchTo()
      Switch to window/tab/frame/parentFrame/innerFrame/alert.
      static java.lang.String title()  
      static void updateHash​(java.lang.String hash)
      Update the hash of the window location.
      static void using​(org.openqa.selenium.WebDriver webDriver, java.lang.Runnable lambda)  
      static SelenideWait Wait()
      Create a org.openqa.selenium.support.ui.FluentWait instance with Selenide timeout/polling.
      static void zoom​(double factor)
      Zoom current page (in or out).
      • Methods inherited from class java.lang.Object

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

      • Selenide

        public Selenide()
    • 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()
      • 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 $​(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
      • $$

        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
      • 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)
      • 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 types
        logLevel - 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.IOException
        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 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.IOException
        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
        timeoutMs - specific timeout in ms
        Returns:
        downloaded File in folder `Configuration.reportsFolder`
        Throws:
        java.io.IOException - if failed to download file