Sunday, February 19, 2017

Lesson #13 -Finding element using the Tag Name attribute

תוצאת תמונה עבור ‪selenium webdriver‬‏Selenium WebDriver provides another strategy to locate web elements using their "Tag Name", in most cases we will use this strategy when we need to find multiple tags in a web page or when working with tables.

In addition,
  • There is no reason to work with this locator when you need a single element.
  • If possible, make sure that the selected TAG is unique.
  • When the element is not found during the code execution, the method returns error type “NoSuchElementException”.
  • The first TAG with this name will be used when executing the code (In a case of duplications).

Code Example

To locate the main title element in my blog, we will now use the "Tag Name" attribute:

<div class="titlewrapper"><h1 class="title"> David Tzemach's Blog </h1></div>

public void FindElementByTagName()
IWebElement WebElement;
IWebDriver Firefox = new FirefoxDriver();
WebElement = Firefox.FindElement(By.TagName("h1"));

No comments:

Post a Comment

My Presentations