Software Development and QA Tips

Dev and QA Tips How Can I Use ID Locator in Selenium Automation Scripts?

How Can I Use ID Locator in Selenium Automation Scripts?

Selenium Automation | By Vakul Gotra | January 25, 2021

How Can I Use ID Locator in Selenium Automation Scripts?

Selenium provides a range of locators to uniquely identify an element on a web page, for instance by ID, name, link text, etc.

One of the most popular ways to locate an element is by ID. In almost all of web pages, ID is considered to be unique for each element.

Syntax:
driver.findElement(By.id("id"))
Below is the example with more details:
<div class="className">

<input id="eID" name= "eName" type="text" > <label>Name</label>

 </div>
Use the following approach to find element by ID:
driver.findElement(By.id("ch_emailID"))

Disclaimer

This publication is for informational purposes only and nothing contained in it should be considered legal advice. We expressly disclaim any warranty or responsibility for damages arising out of this information and encourage you to consult with legal counsel regarding your specific needs. We do not undertake any duty to update previously posted materials.