Selenium Testing Tool Installation and Selenium Webdrivers Locator

Posted By : Meenakshi Koul | 30-May-2022

testing

Loading...

Selenium Testing Tool Installation and Selenium Webdrivers Locators

The Selenium testing tool is used to automate tests cross browsers for web applications. It's used to ensure high-quality web applications, if they are responsive, progressive and giving the better result. Selenium is an open-source tool and it can run the test cases multiple times and making the application much reliable. To learn selenium,one should be aware of Java.

THERE ARE FEW LIMITATION IN SELENIUM ALSO

> It do not provide desktop application support

> We cannot automated REST orSOAP using Selenium.

> programming language is required for script creation for testing

STEPS TO INSTALL SELENIUM

1.Configuration of Java on a machine.

2.We have to Download the latest version of the (JDK) .

3.We are installing JDK as we have to run automation scriptStep.

4.Creating a project and configuring Selenium jars in the form of Java programs

5.Download the latest version of the Java IDE of our choice for e.g for Eclipse.

6.We need to select appropriate version of any IDE depending on our system type- 34 bit or 64 bit.

7.Go to the (Selenium.dev) website and under “Selenium Client & WebDriver Language Bindings”, click on ‘Download’ link for language Java.

8.Unzip the package and place it on any directory as a library folder.

9.Creating a project and configuring Selenium jars.

10.Launch IDE

11.Adding Selenium jars

12.Creating the first Selenium WebDriver project


Example:


import org.openqa.selenium.chrome.ChromeDriver;

public class Hello1 {

public static void main(String[] args)

{

System.setProperty("webdriver.chrome.driver","/home/name/Downloads/driver/chromedriver");

WebDriver driver = new ChromeDriver();

driver.get("https://rfrfr.com");

driver.quit();//closing the driver

}

There are 8 locators in Selenium WebDriver by which we can locate data

1. By Id –

WebElement element = driver.findElement(By.id("xxxxx"));

2. By className –

WebElement element = driver.findElement(By.className("xxxx"));

3. By tagName –

WebElement element = driver.findElement(By.tagName("x"));

4. By name –

WebElement element = driver.findElement(By.name("xxx"));

5. By linkText –

WebElement element = driver.findElement(By.linkText("xxxx"));

6. By partialLinkText –

WebElement element = driver.findElement(By.partialLinkText("xxx"));

7. By cssSelector –

WebElement element = driver.findElement(By.cssSelector("xxx"));

8. By xpath –

WebElement element = driver.findElement(By.xpath("//div[@id='xxx']"));

Example:

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class Hello1 {

public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver","/home/name/Downloads/driver/chromedriver");

WebDriver driver = new ChromeDriver();

driver.get("http://00.000.00.000//");

}

// driver.findElement(By.text("txtUsername")).click();

// driver.findElement(By.partialLinkText("txtUsername")).sendKeys("admin");

// driver.findElement(By.xpath("//span[text()='PSA']")).click();

// driver.findElement(By.id("txtPassword")).click();

// driver.findElement(By.name("username")).sendKeys("username");

// driver.findElement(By.name("password")).sendKeys("password");

// driver.findElement(By.xpath("//*[text()='login']")).click();

// driver.findElement(By.xpath("//button")).click();


We are an ERP application development company that builds custom enterprise solutions for varying industry-specific needs of our clients. We use open-source ERP platforms like Odoo, OFBiz, and ERPNext to build high-quality enterprise applications with custom features. To learn more about our ERP application development services, reach out at [email protected].