How to take locators (xpath, etc) in Selenium and check locators in browser before using it in code to minimize the error?

In this video we will show you how to take locators (xpath/CSS Selector/id/name/ link text/class Name/tagName/partial link text) and checking it in browser (debugger tool) to make sure locator is correct and unique. Locators are nothing but exact location of any element on web page.

I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: programmerworld1990@gmail.com

Syntax:

Text:
<input class="input r4 wide mb16 mt8 username" type="email" value="" name="username" id="username" aria-describedby="error" style="display: block;">

How to write locator for above HTML code;
Xpath Syntax: //tagName[@attribute=’value’]
Xpath: //input[@name=’username’]


CSS selector Syntax: Tagname[attribute=’value’]
Tagname#id(id value)   (another syntax)
Tagname.classname (another syntax)
[attribute=’value’] (another syntax)

Css Selector:
Input[name=’username’]
Input#id(username)
Input. input r4 wide mb16 mt8 username
[name=’username’]
Another example of HTML code:
<span id="category-header-name" class="tax-category__nav--title-name active">Guide Not Allowed</span>
Text() and Contains(text()) syntax:
//htmltag[text()=’value’]
//htmltag[contains(text(), ‘value’)]
//span[text()=’ Guide Not Allowed’]
//span[contains(text(),’Guide’)]

Code:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class RediffE2E {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.setProperty("webdriver.chrome.driver", "C:\\work\\Selenium\\chromedriver_win32_version98\\chromedriver.exe");
		WebDriver driver = new ChromeDriver();
		driver.get("https://www.rediff.com/");
		driver.findElement(By.cssSelector("a[title*='Sign in']")).click();
		driver.findElement(By.xpath("//input[@name='login']")).sendKeys("adadad");
		driver.findElement(By.cssSelector("input[name='passwd']")).sendKeys("afsfsfs");
		//driver.close();
		driver.findElement(By.xpath("//input[contains(@name, 'procee')]")).click();
}
}

Leave a Reply

%d bloggers like this:
Available for Amazon Prime