Page tree
Skip to end of metadata
Go to start of metadata

Last updated: Jan 08, 2020 14:56

by Nato Vasilevski

There are errors in the reporting and elements that are not found with error like: FIND_ELEMENT_FAILURE: No element found.

To create this, I have used a simple scenario where I am opening the perfecto.io site and I search for an element that is for sure not there. In the first case I am using findElements and in the other case I am using findElement. Continue to the end of the article to find out the results.


The findElements method

Code sample:

reportiumClient.testStart("FindElements", new TestContext("NatoTest", "findElements"));
driver.get("perfecto.io");
List<WebElement> elements1 = driver.findElementsByXPath("//*[@class=\"gLFyfg\"]");
reportiumClient.testStop(TestResultFactory.createSuccess());


Result in the Perfecto Reporting:

And the error itself:

Here we see that although the expected result hasn’t been found, BUT the test is marked as successful.



Now let’s see what happens when we use findElement method:

The findElement method

Code sample:

reportiumClient.testStart("FindElement", new TestContext("NatoTest", "findElement"));
driver.get("perfecto.io");
WebElement element1 = driver.findElementByXPath("//*[@class=\"gLFyfg\"]");
reportiumClient.testStop(TestResultFactory.createSuccess());


Result in the Perfecto Reporting:


And the error itself:

Now we see that the expected result is not found, AND the test is marked as failed.



Why is this happening?

As defined by Selenium WebDriver API the method findElement() should be used when the element is expected to exist. If the element doesn’t exist it is an error and the command is marked as failed. The method findElements() should be used for checking whether one or more elements, that fit the find criteria, exist. If no element is found, which is a valid situation, an empty list is returned and the command is marked as successful.