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
Step 2: Name The Java Project
A new window will be open to prompting to enter a Project Name. Provide a meaningful name
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
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
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.
Step 6: Selenium WebDriver Coding
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();
}
}
Step 7: Run The Java Project
Right-click on the class then select 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