How can I use ID locator in Selenium automation scripts?

Can anyone please tell me how can I use ID locator in Selenium automation scripts, recently i am trying to study it.

Hey Darran!

You can use the syntax given below to use the ID locator in Selenium scripts.

driver.findElement("remember "));

Here I am taking an example of a Facebook login page where I’ll log in using ID locators for interacting with the WebElement object.

Following are the DOM structure for the login fields like email, password, and login button.

<input type="email" class="inputtext" name="email" id="email" value="" data-testid="my_email">

<input type="password" class="inputtext" name="pass" id="pass" data-testid="my_pass">

<input value="Log In" aria-label="Log In" data-testid="fb_login_button" type="submit" id="u_0">

Here is the screenshot of the Facebook login page highlighting the above DOM structures.

For further information, refer to our blog Making The Move With ID Locator In Selenium WebDriver