
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>
[TestMethod]
public
void FindElementByTagName()
{
IWebElement WebElement;
IWebDriver Firefox = new FirefoxDriver();
Firefox.Navigate().GoToUrl("http://www.machtested.com/");
WebElement = Firefox.FindElement(By.TagName("h1"));
}
No comments:
Post a Comment