Class WebDriverUtils


  • public final class WebDriverUtils
    extends java.lang.Object
    Provides some utilities for handling the Selenium WebDriver
    • Method Detail

      • switchToWindow

        public static boolean switchToWindow​(java.util.function.Predicate<org.openqa.selenium.WebDriver> predicate)
      • switchToWindow

        public static boolean switchToWindow​(org.openqa.selenium.WebDriver mainWebDriver,
                                             java.util.function.Predicate<org.openqa.selenium.WebDriver> predicate)
      • findWindowAndSwitchTo

        public static boolean findWindowAndSwitchTo​(java.lang.String windowTitle)
        Finds a window by matching title and will switch to it.
        Parameters:
        windowTitle - String Title of the window to switch to.
        Returns:
        true if switching was successful.
      • findWindowAndSwitchTo

        public static boolean findWindowAndSwitchTo​(java.lang.String windowTitle,
                                                    org.openqa.selenium.WebDriver driver,
                                                    java.lang.String... excludeWindowHandles)
        Finds a window by matching title and will switch to it.
        Parameters:
        windowTitle - String Title of the window to switch to.
        driver - WebDriver object or null (then the default session will be used)
        excludeWindowHandles - String array of window handles that should not be switch to.
        Returns:
        true if switching was successful.
      • findWindowAndSwitchTo

        public static boolean findWindowAndSwitchTo​(java.lang.String windowTitle,
                                                    java.lang.String urlContains,
                                                    org.openqa.selenium.WebDriver driver,
                                                    java.lang.String... excludeWindowHandles)
        Finds a window by matching title and will switch to it.
        Parameters:
        windowTitle - StringTitle of the window to switch to.
        driver - WebDriver object or null (then the default session will be used)
        excludeWindowHandles - String array of window handles that should not be switch to.
        Returns:
        true if switching was successful.
      • findElementByLocation

        public static org.openqa.selenium.WebElement findElementByLocation​(org.openqa.selenium.WebDriver driver,
                                                                           int x,
                                                                           int y)
        Finds an element by it's location using Selenium features and utilities
        Parameters:
        driver - WebDriver
        x - int - coordinate
        y - int - coordinate
        Returns:
        org.openqa.selenium.WebElement
      • getLowestWebDriver

        public static org.openqa.selenium.WebDriver getLowestWebDriver​(org.openqa.selenium.WebDriver driver)
        Will search for the deepest WebDriver in the Wrapped-WebDriver-Chain
        Parameters:
        driver - WebDriver
        Returns:
        WebDriver
      • getSessionId

        public static java.lang.String getSessionId​(org.openqa.selenium.WebDriver driver)
        Deprecated.
        Use WebDriverSessionsManager.getSessionContext(WebDriver) instead // TODO Should be package private
        Will return Selenium session UUID of WebDriver session
        Parameters:
        driver - WebDriver
        Returns:
        String
      • getViewport

        public static org.openqa.selenium.Rectangle getViewport​(org.openqa.selenium.WebDriver webDriver)
        Deprecated.
      • keepWebDriverAlive

        public static WebDriverKeepAliveSequence keepWebDriverAlive​(org.openqa.selenium.WebDriver driver,
                                                                    int intervalSleepTimeInSeconds,
                                                                    int durationInSeconds)
        Initialize a WebDriverKeepAliveSequence and runs it with Timer in given interval. This will keep the WebDriver alive, when acting with another driver in same test or waiting for something to happen in main thread. NOTE: Please use this method with care AND clean up your Sequence by calling removeKeepAliveForWebDriver(WebDriver)
        Parameters:
        driver - WebDriver
        intervalSleepTimeInSeconds - int
        durationInSeconds - int
        Returns:
        WebDriverKeepAliveSequence
      • removeKeepAliveForWebDriver

        public static void removeKeepAliveForWebDriver​(org.openqa.selenium.WebDriver driver)
        Removes an active WebDriverKeepAliveSequence if present.
        Parameters:
        driver - WebDriver the current driver