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"));



3 comments:

  1. My friend Suggest me this blog and I can say this is the best blog to get the basic knowledge.Thank you so much for this Selenium Training in Chennai blog

    ReplyDelete
  2. Best blog.Got to learn new things.Thanks for this Blog SAP HR Training in Chennai

    ReplyDelete
  3. Great place to learn about the new things and got great knowledgeSAP MM Training in Chennai

    ReplyDelete