Selenium Locators
Selenium Locators
Now these interactions can be created using Locators. These locators are used to
identify webElements within a web page. These elements can vary from images,
buttons, dropDowns, calendars, input fields etc.
Example - driver.findElement(By.id("depart-from"));
Example - driver.findElement(By.name("signInButton"));
2) Partial LinkText : Accessing links using a portion of their link text is done using
the By.partialLinkText() method.
Example: driver.findElement(By.partialLinkText("here")).click();
driver.findElement(By.tagName("input")).sendKeys("JAVA");
1) ID
2) Class
3) Attribute
P.T.O
Majorly there are 3 ways to find elements using ClassName in CSS selectors:-
Examples:
Majorly there are 1 way to find elements using Attribute in CSS selectors:-
● driver.findElement(By.cssSelector(“<tagname>[href=’<href value>’]”));
Examples:
1. driver.findElement(By.cssSelector("a[href='/login']"));
Note: Other attributes like placeholder, text etc. can also be used!
Example: html/body/form/input[3]
driver.findElement(By.xpath("//body")).sendKeys(Keys.SPACE);
Example: //form/input[3]
driver.findElement(By.xpath("//body")).sendKeys(Keys.SPACE);
P.T.O
Syntax: xpath-‐to-‐some-‐element//descendant::<tag>
Example: //[@id='rt-feature']//descendant::a
Note: Above 4 mentioned types of XPath are also called XPath Axes.