Time for action – using findElement() - Selenium

In this section we are going to look at using the find Element call that is on the WebDriver object. This is how we can normally find elements using Selenium WebDriver.

  1. Open your Java IDE. Intellij or Eclipse are the most used that you could use.

  2. We are going to use the command:

    driver.get("http://book.theautomatedtester.co.uk") driver.findElement(By.linkText("Chapter1"));
  3. Run your test.

What just happened?

We have just seen that we can find an element by passing in the By object. This is a static class that gives people a mechanism for finding elements, as we did earlier in the chapter. This will throw a No Such Element Exception if it cannot find the element.

Let's now have a look at finding multiple elements.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Selenium Topics