Class AbstractWebDriver

    • Constructor Detail

    • Method Detail

      • getSupportJavascript

         Boolean getSupportJavascript()

        Whether the driver supports javascript. Web drivers such as MockDriver do not support javascript.

      • isRecovered

         Boolean isRecovered()

        Whether the driver is recovered from the browser's tab list.

      • setRecovered

         Unit setRecovered(Boolean isRecovered)

        Whether the driver is recovered from the browser's tab list.

      • isReused

         Boolean isReused()

        Whether the driver is recovered and is reused to serve new tasks.

      • setReused

         Unit setReused(Boolean isReused)

        Whether the driver is recovered and is reused to serve new tasks.

      • getState

         AtomicReference<WebDriver.State> getState()

        The state of the driver.

        • State.INIT: The driver is initialized.

        • State.READY: The driver is ready to work.

        • State.WORKING: The driver is working.

        • State.RETIRED: The driver is retired and should be quit as soon as possible.

        • State.QUIT: The driver is quit.

      • isRetired

         Boolean isRetired()

        Whether the driver is retired and should be quit as soon as possible.

      • isCanceled

         Boolean isCanceled()

        Whether the current driver task is canceled and should return as soon as possible.

      • getBrowser

         Browser getBrowser()

        The browser of the driver. The browser defines methods and events to manipulate a real browser.

      • free

         Unit free()

        Mark the driver as free, so it can be used to fetch a new page.

      • startWork

         Unit startWork()

        Mark the driver as working, so it can not be used to fetch another page.

      • retire

         Unit retire()

        Mark the driver as retired, so it can not be used to fetch any page, and should be quit as soon as possible.

      • cancel

         Unit cancel()

        Mark the driver as canceled, so the fetch process should return as soon as possible, and the fetch result should be dropped.

      • jvm

         JvmWebDriver jvm()

        Returns a JvmWebDriver to support other JVM languages, such as java, clojure, scala, and so on, the other JVM languages might have difficulty to handle kotlin suspend methods.

      • navigateTo

         Unit navigateTo(String url)

        Returns the main resource response. In case of multiple redirects, the navigation will resolve with the first non-redirect response.

        Parameters:
        url - URL to navigate page to.
      • location

         String location()

        Returns the document's location evaluated by javascript.

        In javascript, the window.location, or document.location, is a read-only property returns a Location object, which contains information about the URL of the document and provides methods for changing that URL and loading another URL.

        To retrieve just the URL as a string, the read-only document.URL property can also be used.

      • baseURI

         String baseURI()

        Returns the document's baseURI evaluated by javascript.

        In javascript, the baseURI is a property of Node, it's the absolute base URL of the document containing the node. A baseURI is used to resolve relative URLs.

        The base URL is determined as follows:

        • By default, the base URL is the location of the document (as determined by window.location).

        • If the document has an <base> element, its href attribute is used.

      • waitForSelector

         Long waitForSelector(String selector, Long timeoutMillis)

        Returns when element specified by selector satisfies {@code state} option. Returns the time remaining until timeout.

      • waitForSelector

         Long waitForSelector(String selector)

        Returns when element specified by selector satisfies {@code state} option.

      • evaluateSilently

         Object evaluateSilently(String expression)

        Executes JavaScript in the context of the currently selected frame or window. The script fragment provided will be executed as the body of an anonymous function.

        All possible exceptions are suppressed and do not throw.

        Parameters:
        expression - Javascript expression to evaluate
        Returns:

        Remote object value in case of primitive values or JSON values (if it was requested).

      • scrollDown

         Unit scrollDown(Integer count)

        The current page frame scrolls down for count times.

        Parameters:
        count - The times to scroll down.
      • scrollUp

         Unit scrollUp(Integer count)

        The current page frame scrolls up for count times.

        Parameters:
        count - The times to scroll up.
      • scrollToTop

         Unit scrollToTop()

        The current page frame scrolls to the top.

      • scrollToMiddle

         Unit scrollToMiddle(Float ratio)

        The current page frame scrolls to the middle.

        Parameters:
        ratio - The ratio of the page to scroll to, 0.0 means the top, 1.0 means the bottom.
      • outerHTML

         String outerHTML()

        Returns the document's HTML markup.

        If the document does not exist, returns null.

        Returns:

        The HTML markup of the document.

      • outerHTML

         String outerHTML(String selector)

        Returns the node's HTML markup, the node is located by selector.

        If the node does not exist, returns null.

        Parameters:
        selector - The selector to locate the node.
        Returns:

        The HTML markup of the node.

      • selectFirstTextOrNull

         String selectFirstTextOrNull(String selector)

        Returns the node's text content, the node is located by selector.

        If the node does not exist, returns null.

        Parameters:
        selector - The selector to locate the node.
        Returns:

        The text content of the node.

      • selectTexts

         List<String> selectTexts(String selector)

        Returns the nodes' text contents.

        If the nodes do not exist, returns an empty list.

        Parameters:
        selector - The selector to locate the nodes.
        Returns:

        The text contents of the nodes.

      • selectFirstAttributeOrNull

         String selectFirstAttributeOrNull(String selector, String attrName)

        Returns the node's attribute value, the node is located by selector, the attribute is attrName.

        If the node does not exist, or the attribute does not exist, returns null.

        Parameters:
        selector - The selector to locate the node.
        attrName - The attribute name to retrieve.
        Returns:

        The attribute value of the node.

      • selectAttributes

         List<String> selectAttributes(String selector, String attrName)

        Returns the nodes' attribute values, the nodes are located by selector, the attribute is attrName.

        If the nodes do not exist, or the attribute does not exist, returns an empty list.

        Parameters:
        selector - The selector to locate the nodes.
        attrName - The attribute name to retrieve.
        Returns:

        The attribute values of the nodes.

      • clickTextMatches

         Unit clickTextMatches(String selector, String pattern, Integer count)

        This method clicks an element with selector whose text content matches pattern, and then focuses it. If there's no element matching selector, or the element's text content doesn't match pattern, nothing to do.

        Parameters:
        selector -
        • A {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | selector } of an element to focus. If there are multiple elements satisfying the selector, the first will be focused.

      • check

         Unit check(String selector)

        This method check an element with selector. If there's no element matching selector, nothing to do.

        Parameters:
        selector -
        • A {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | selector } of an element to check. If there are multiple elements satisfying the selector, the first will be focused.

      • uncheck

         Unit uncheck(String selector)

        This method uncheck an element with selector. If there's no element matching selector, nothing to do.

        Parameters:
        selector -
        • A {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | selector } of an element to uncheck. If there are multiple elements satisfying the selector, the first will be focused.

      • newJsoupSession

         Connection newJsoupSession()

        Create a new Jsoup session with the last page's context, which means, the same headers and cookies.

      • loadJsoupResource

         Connection.Response loadJsoupResource(String url)

        Load the url as a resource with Jsoup rather than browser rendering, with the last page's context, which means, the same headers and cookies.