Monday 25 April 2016

Selenium WebDriver

Locating UI Elements

By ClassName

Class” in this case refers to the attribute on the DOM element. Often in practical use there are many DOM elements with the same class name, thus finding multiple elements becomes the more practical option over finding the first element.


Example of how to find an element that looks like this:

<div class="cheese"><span>Cheddar</span></div><div class="cheese"><span>Gouda</span></div>

    List<WebElement> cheeses = driver.findElements(By.className("cheese"));


By TagName

The DOM Tag Name of the element.

Example of how to find an element that looks like this:

<iframe src="..."></iframe>

WebElement frame = driver.findElement(By.tagName("iframe"));


By Name

Find the input element with matching name attribute.

Example of how to find an element that looks like this:

<input name="cheese" type="text"/>

WebElement cheese = driver.findElement(By.name("cheese"));



No comments:

Post a Comment