Class HtmlUnitElementFinder.HtmlUnitElementLocator

java.lang.Object
org.openqa.selenium.htmlunit.HtmlUnitElementFinder.HtmlUnitElementLocator
Direct Known Subclasses:
HtmlUnitElementFinder.FindByClassName, HtmlUnitElementFinder.FindByCssSelector, HtmlUnitElementFinder.FindByID, HtmlUnitElementFinder.FindByLinkText, HtmlUnitElementFinder.FindByName, HtmlUnitElementFinder.FindByPartialLinkText, HtmlUnitElementFinder.FindByRelativeLocator, HtmlUnitElementFinder.FindByTagName, HtmlUnitElementFinder.FindByXPath
Enclosing class:
HtmlUnitElementFinder

public abstract static class HtmlUnitElementFinder.HtmlUnitElementLocator extends Object
Base class for element locators used by HtmlUnitElementFinder.

Provides common utilities for finding elements within a page or another element, as well as methods for retrieving the last loaded page and extracting values from By locators.

  • Constructor Details

    • HtmlUnitElementLocator

      public HtmlUnitElementLocator()
  • Method Details

    • findElement

      public org.openqa.selenium.WebElement findElement(HtmlUnitDriver driver, org.openqa.selenium.By locator)
      Finds a single element on the given page using the provided locator.

      If multiple elements match, only the first is returned. If no element is found, a NoSuchElementException is thrown.

      Parameters:
      driver - the driver representing the browser/page context
      locator - the locator strategy to use
      Returns:
      the first matching WebElement
      Throws:
      org.openqa.selenium.NoSuchElementException - if no element matches the locator
    • findElements

      public abstract List<org.openqa.selenium.WebElement> findElements(HtmlUnitDriver driver, org.openqa.selenium.By locator)
      Finds multiple elements on the given page using the provided locator.
      Parameters:
      driver - the driver representing the browser/page context
      locator - the locator strategy to use
      Returns:
      a list of matching WebElement objects
    • findElement

      public org.openqa.selenium.WebElement findElement(HtmlUnitWebElement element, org.openqa.selenium.By locator)
      Finds a single element within a specific HtmlUnitWebElement.

      If multiple elements match, only the first is returned. If no element is found, a NoSuchElementException is thrown.

      Parameters:
      element - the element within which to search
      locator - the locator strategy to use
      Returns:
      the first matching WebElement
      Throws:
      org.openqa.selenium.NoSuchElementException - if no element matches the locator
    • findElements

      public abstract List<org.openqa.selenium.WebElement> findElements(HtmlUnitWebElement element, org.openqa.selenium.By locator)
      Finds multiple elements within a specific HtmlUnitWebElement.
      Parameters:
      element - the element within which to search
      locator - the locator strategy to use
      Returns:
      a list of matching WebElement objects
    • getRemotable

      protected static org.openqa.selenium.By.Remotable getRemotable(org.openqa.selenium.By locator)
      Converts a By locator to a By.Remotable locator.
      Parameters:
      locator - the locator to convert
      Returns:
      the remotable locator
      Throws:
      IllegalStateException - if the locator is not remotable
    • getLastPage

      protected SgmlPage getLastPage(HtmlUnitDriver driver)
      Retrieves the last loaded SgmlPage from the driver.
      Parameters:
      driver - the driver representing the browser/page context
      Returns:
      the last loaded SgmlPage
      Throws:
      IllegalStateException - if the current page is not an SgmlPage
    • getValue

      protected static String getValue(org.openqa.selenium.By locator)
      Extracts the string value from a remotable By locator.
      Parameters:
      locator - the locator from which to extract the value
      Returns:
      the string value of the locator