• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

SoftwareTestingo - jira selenium protractor testing sdlc agile methodology

Java Selenium Tutorial & Testing Interview Questions

  • Home
  • Interview Questions
  • Java
  • Java Programs
  • Test Cases
  • Selenium
  • Manual Testing
  • Difference
  • Search
SoftwareTestingo » Selenium » Selenium Tutorial » ID Locators In Selenium WebDriver With Examples

ID Locators In Selenium WebDriver With Examples

Last Updated on: November 29, 2019 By Softwaretestingo Admin

  • Selenium ID Locators

In our previous post, we have discussed the different locators of selenium, and in this post, we are going to discuss “How we can locate Element By ID locator”.

Selenium ID Locators

ID locators are one of the most popular and famous ways to identify the elements in the web page. As per the W3C standard, every element supposes to be unique, which makes this ID locators one of the reliable locators.

ID locator is considered as one of the safest and fastest locator options and for every automation testers its the first choice when there are multiple-choice to locate the web elements.

Let’s take an example to understand how the ID locator work

Scenario:

  • Launch Mozilla Firefox
  • Open Gmail On Firefox Browser
  • Locate the Enter Email Id Text box and enter an email Id with using the ID locator.

Code Snippet:

public class Locators {

public static void main (String [] args){
// Open browser
WebDriver driver = new FirefoxDriver();
// Open Application
driver.get("<a href="https://www.gmail.com/" target="_blank" rel="noopener" data-saferedirecturl="https://www.google.com/url?hl=en&amp;q=https://www.gmail.com&amp;source=gmail&amp;ust=1475225889620000&amp;usg=AFQjCNGWiJEPM95P3VkSISyTSrTuSE2t5A">https://www.gmail.<wbr />com</a>");
// Locate the element using ID locator and enters test value "Software Testing Material."
driver.findElement(By.id("<wbr />Email")).sendKeys("Software Testing Material");

}
}

If you run the above Java program, then you will find out that Gmail will be launched in the Mozilla Firefox browser, after that it will enter the email address in the email id text box. I hope this gives you a clear understanding of how Id locator in Selenium works.

But since browsers do not make this thing mandatory that for each element the ID should be unique, developers take advantage of this that’s why for some of the elements in the web page ID is not present as a part of an attribute or due to auto-generated some elements have the same ID. Due to the mentioned issues, wen needs to use the other locators.

    Filed Under: Selenium Tutorial

    Reader Interactions

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    Primary Sidebar

    Important Links

    • Software Testing Jobs
    • Core Java Tutorial
    • Selenium Tutorial
    • Manual Testing Concepts Tutorial
    • Software Testing Interview Questions
    • Java Interview Questions
    • 170+ Java Programs
    • 60+ Java Selenium Interview Programs
    • Manual Test Cases
    • Software Testingo Interview Tips
    • www.softwaretestingo.com
    • You Can Share With Us Here

    Categories

    Copyright © 2019 SoftwareTestingo.com ~ Contact Us ~ Sitemap ~ Privacy Policy