TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Selenium

Find elements using Selenium Locators

Overview

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:

https://www.selenium.dev/

Related Posts

Windows 10 Settings

Selenium /

Add Microsoft Webdriver on Windows OS

Download Selenium Components

Selenium /

Getting Started with Selenium Webdriver

LambdaTest Testing Cloud SaaS Platform

Selenium /

LambdaTest – Testing Cloud SaaS Platform

Selenium /

Selenium 3.0 and Mozilla GeckoDriver

SauceLabs Website

Selenium /

Run an Example Test on SauceLabs

‹ RemoteWebDriver Tutorial› Selenium WebDriver Questions

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version