Steps for Locating Strategies By ID Using Java

Step1:Create a Java Project In Eclipse IDE

Launch Eclipse IDE and create a new project by navigating

File –>New –>Java Project


Creating new project

Step 2: Name The Java Project

A new window will be open to prompting to enter a Project Name. Provide a meaningful name

project name Locators_Demo

Step 3:Download Selenium and Configure Build Path

A new project is created with the name Locators_Demo. Then right-click on a project to configure selenium jar files with IDE.

before you should download Selenium WebDriver for Java.

link: Selenium WebDriver

Right-click on project–> Build Path –>Configure Build Path –>Class Path–>Add External Jars –>Select All Jars–>Apply And Close

Configure Build Path


Add External Jars


Add External Jars


Add External Jars

Step 4: Download Chrome Driver

Right-click on Project to create a new folder to store the Chrome driver

Download a compatible version of Chrome driver for your Chrome browser then extract the files into the Chrome driver folder.

Chrome Driver Download Link: Chrome Driver

Create a folder


Step 5 Create a New Class File

Right-click on the src folder then create a package name as com. selenium. Test under this package create one class name as ByIdDemo the click on finish. Then the project folder structure is shown as the below pictures.

Create Class


ByIdDemo.java


Step 6: Selenium WebDriver Coding

Java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class ByIdDemo {

    public static void main(String[] args) {
        //System property for chrome driver
        System.setProperty("webdriver.chrome.driver","./ChromeDriver/chromedriver-win32/chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.get("https://www.facebook.com/");
        driver.findElement(By.id("email")).sendKeys("abc@gmail.com");
        driver.findElement(By.id("pass")).sendKeys("12345");
        driver.findElement(By.name("login")).click();
        
        
    }

}


Final test case

Step 7: Run The Java Project

Right-click on the class then select Run as Java Application

Run As Java Application

Output :

Face Facebook login page will automated by the opening typing email and password and then clicking on the login button.

Locating Strategies By ID Using Java

Here we are going to discuss locating a particular web element using the value of its id

Table of Content

  • Steps for Locating Strategies By ID Using Java
  • Conclusion
  • FAQ’s

Similar Reads

Steps for Locating Strategies By ID Using Java

Step1:Create a Java Project In Eclipse IDE...

Conclusion

In conclusion, Id is a locator which is present under the By class. Id locator which is unique for every element in the DOM page that’s why an ID can uniquely identify an element....

Frequently Asked Questions based on Locating Strategies By ID Using Java:

What is Selenium?...

Contact Us