Posted

3 minutes read

Load Focus is a Cloud Load Testing Service. You can stress your app/website/API with thousands of concurrent users from all over the world.

In order to write UI tests with Selenium WebDriver you need to be able to identify web page elements fast and in an accurate way. You don’t want to revisit these selectors very often so you must choose the right selector from the beginning.

There are some browser tools that you can use in order to identify web elements in the DOM easier. These are:

  • Firebug for Firefox
  • Google Developer Tools for Chrome
  • Web Inspector for Safari

You can also create automated website tests for free with LoadFocus.com.

Selenium WebDriver API supports different possibilities to identify elements: by ID, by CLASS, by NAME, by CSS selector, by XPath, by TAG name. Also you define your custom selector in order to interact with the elements.

It’s always a good practice to assign unique IDs to elements, also names and classes in order to be more usable for automatic UI tests. If that is not possible you’ll need to use advanced or XPath selector to interact with those elements. The most popular selectors are the CSS selectors due to performance and simplicity reasons.

To inspect an element you just have to open the desired web page, right-click the desired element and click on Inspect Element. A new panel will open showing the desired element. Also you can inspect other elements by clicking on the cursor in the top left side of the Developer Tools or Firebug panels and hovering page elements.

Locating Elements with Selenium WebDriver, findElement() method returns and WebElement and findElements() returns a list of WebElements.

1. By ID:

 in Java: driver.findElement(By.id("element id")) 

2. By CLASS:

 in Java: driver.findElement(By.className("element class"))

3. By NAME:

in Java: driver.findElement(By.name("element name"))

4. By TAGNAME:

 in Java: driver.findElement(By.tagName("element html tag name"))

See more details








Thanks for reading. I hope you learned something interesting about React!
If you found this article useful, please share it with others. Don’t forget to subscribe to get notified for the upcoming articles.