Skip to content

Include locator in error message when element is not found #164

Description

@liefke

Let's say I have the following code:

HtmlUnitDriver driver = ...
List<WebElement> elements = Stream.of(
    By.tagName("h1"), 
    By.tagName("h2"), 
    By.cssSelector("h3"), 
    By.cssSelector("h4")
  ).map(driver::findElement).toList();
...

When one of that elements is missing, I get different error messages:

  • org.openqa.selenium.NoSuchElementException: Unable to locate element with name: 'h1'
  • org.openqa.selenium.NoSuchElementException: Unable to locate element with name: 'h2'
  • org.openqa.selenium.NoSuchElementException: Returned node (null) was not a DOM element
  • org.openqa.selenium.NoSuchElementException: Returned node (null) was not a DOM element

I hope you see what the problem is: While I can identify what is missing from the error message for By.tagName, I can't do that from the error message for By.cssSelector, what makes it hard to find the root cause for an error.

So I'd like to ask if we can include the specific locator in each error message of HtmlUnitDriver.findElement.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions