Find Elements using Selenium Locators
Find Elements using Selenium Locators
In this tutorial, we will discuss about finding elements on a web page using Selenium Locators. By is the locating mechanism to find element(s) on a web page using locators.
We can locate web elements in Selenium with the help of methods like:
- driver.findElement()
- driver.findElements()
The first method is used to find a single element on the page. The second method is mostly used to find multiple elements.
Types of Locators
https://www.testingdocs.com/different-types-of-locators-in-selenium-webdriver/
We will look at close some of the locators supported by Selenium.
By.id()
https://www.testingdocs.com/selenium-find-element-using-by-id-attribute/
By.name()
https://www.testingdocs.com/selenium-find-element-using-by-name-example/
By.tagName()
https://www.testingdocs.com/locate-elements-by-tagname-in-selenium-webdriver/
LinkText : By.linkText()
https://www.testingdocs.com/find-link-using-by-linktext-in-selenium/
By.partialLinkText()
https://www.testingdocs.com/find-links-using-by-partial-link-text-in-selenium/
By.className()
Code :
WebElement element = findElement(By.className(“b_searchbox”));
By.cssSelector()
CSS locator mechanism can be used to identify web elements. CSS executes faster than XPath. CSS locator uses CSS selectors to find the elements in the webpage.
For example, the following statement first locates a web element satisfying the selector pattern
div#searchBox {text-align: center;}
WebElement search = driver.findElement(By.cssSelector(“div#searchBox”));
XPath : By.xpath()
https://www.testingdocs.com/find-elements-by-xpath-in-selenium/
—
Selenium Tutorials on this website:
https://www.testingdocs.com/selenium-webdriver-tutorial/
Official Website: