02_02_Selenium WebDriver Locators_Part1
02_02_Selenium WebDriver Locators_Part1
Selenium WebDriver
Locators
May-2019
Internal | RBVH/ENG1 | 6/24/2014 | © Robert Bosch Engineering and Business Solutions Vietnam Company Limited 2013. All
2
rights reserved, also regarding any disposal, exploitation, reproduction, editing, distribution, as well as in the event of
applications for industrial property rights.
RBVH/ENG1
Internal | RBVH/ENG1 | 6/24/2014 | © Robert Bosch Engineering and Business Solutions Vietnam Company Limited 2013. All
rights reserved, also regarding any disposal, exploitation, reproduction, editing, distribution, as well as in the event of
applications for industrial property rights.
This is the most common way of locating elements since ID's are
supposed to be unique for each element.
Target Format: id=id of the element
Locating by ID
Locating elements by name are very similar to locating by ID,
except that we use the "name=" prefix instead.
Target Format: name=name of the element
Locating by Name
Locating by Link Text
This type of locator applies only to hyperlink texts. We access the link
by prefixing our target with "link=" and then followed by the
hyperlink text.
Target Format: link=link_text
Locating by XPath
WebElement elementName =
driver.findElement(By.LocatorStrategy("LocatorValue"));
Locator Strategy can by any of the
following values.
ID
Name
Class Name
Tag Name
Link Text
Partial Link Text
XPATH
FindElement
Locator Value is the unique value using which a web element can be
identified. It is the responsibility of developers and testers to make
sure that web elements are uniquely identifiable using certain
properties such as ID or name.
Example:
WebElement loginLink =
driver.findElement(By.linkText("Login"));
FindElements command syntax:
Reference
https://www.guru99.com/selenium-tutorial.html
15
Internal | RBVH/ENG1 | 6/24/2014 | © Robert Bosch Engineering and Business Solutions Vietnam Company Limited 2013. All
rights reserved, also regarding any disposal, exploitation, reproduction, editing, distribution, as well as in the event of
applications for industrial property rights.