Automation 4 absolute beginners - Selenium WebDriver_Locators

WebElement Location Statergies:

To get know the basic usage of HTML tags -Click Here

All the elements on the web page are called WebElements in selenium webdriver.
To identify the elements on the Web page uniquely, Selenium has provided support with the following locators

1. ID
2. ClassName
3. TagName
4. Name
5. LinkText
6. Partial LinkText
7. CSS Selector
8. XPath

1. ID
ID may be generated dynamically, at that instant of time,this might fail

driver.findElement(By.ID("IDValue"));

2. ClassName
Multiple classes may have same ClassName, such as Radio buttons, Check boxes. So it might not be possible to identify an individual element uniquely. But when required to identify a group of elements, it will be useful

driver.findElement(By.ClassName("Value"));

3. TagName
Multiple Elements may have the same TagName, So it might not be possible to identify an individual element uniquely. But when required to identify a group of elements, it will be useful

driver.findElements(By.tagName("input"));

4. Name
This gives an extra information to the Tag

driver.findElements(By.name("enabledTextField"));

5. LinkText
We can identify only the links available on the web page using this locator

driver.findElement(By.linkText("logout"));

6. Partial LinkText
When we are not sure of the entire link text or want to use only part of the link text, we can use this locating mechanism to identify the link element

driver.findElement(By.partialLinkText("Cont"));

7. XPath
driver.findElement(By.xpath("Relative_XPath of web element"));

8. CSS Selector
driver.findElement(By.cssSelector("CSS Path of Web element"));

Click Here to learn more about CSS & XPath identification

Comments

Popular posts from this blog

QA's approach 2 Java - Understanding Static context

Selenium 4 absolute beginners - How to create Batch execution file

Technologies - Log4J - Create Log4j Configuration File - Where ? How ? What ?