Debomita Bhattacharjee has Published 867 Articles

What is xpath in Selenium?

Debomita Bhattacharjee

Debomita Bhattacharjee

Updated on 10-Jun-2020 13:13:52

2K+ Views

Xpath is one of the most important locators used in Selenium for identifying web elements. It works in the following ways −It navigates through the Document Object Model (DOM) with the help of elements and their attributes for identification.Although it helps to locate the elements uniquely, it is slower in ... Read More

What are the different methods of creating a css expression?

Debomita Bhattacharjee

Debomita Bhattacharjee

Updated on 10-Jun-2020 13:09:03

154 Views

The different methods of creating a css expression are listed below −Using a class as css selectorThis will select all the web elements of that particular class. (Represented by (.) for example - .classname)Using an id as css selector.This will select the web element of that particular id. (Represented by ... Read More

How to identify the nth sub element using xpath?

Debomita Bhattacharjee

Debomita Bhattacharjee

Updated on 10-Jun-2020 13:06:19

4K+ Views

We can identify the nth sub element using xpath in the following ways −By adding square brackets with index.By using position () method in xpath.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class SubElement {    public static void main(String[] args) {       ... Read More

Among id, name, xpath and css, which locator should be used?

Debomita Bhattacharjee

Debomita Bhattacharjee

Updated on 10-Jun-2020 13:04:03

309 Views

Each of the locators has some significance. If the page contains uniqueattribute values, we should use them first. However if there are no unique elements, we should use css selector as it is more effective in terms of speed.Css also has a drawback that we cannot traverse from child to ... Read More

How to identify elements based on text visible on page in Selenium?

Debomita Bhattacharjee

Debomita Bhattacharjee

Updated on 10-Jun-2020 12:59:04

2K+ Views

To identify elements based on text visible on page, text() method is used in xpath.Syntax −driver.findElement(By.xpath("//tagname[text()=’value’]"))Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class TextMatch {    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ... Read More

How to identify the elements by partially comparing to its attributes in Selenium?

Debomita Bhattacharjee

Debomita Bhattacharjee

Updated on 10-Jun-2020 12:57:32

997 Views

We can identify elements by partially comparing to its attributes in Selenium with the help of regular expression. In xpath, there is contains () method. It supports partial matching with the value of the attributes. This method comes as useful while dealing with elements having dynamic values in their attributes.Syntax driver.findElement(By.xpath("//tagname[contains(@attributes, ... Read More

What are the various locators that Selenium supports?

Debomita Bhattacharjee

Debomita Bhattacharjee

Updated on 10-Jun-2020 12:44:25

151 Views

The various types of locators that Selenium support are listed below −ID − This attribute is unique for every element.Syntax − driver.findElement(By.id("")).Name − This attribute is not unique for every element.Syntax − driver.findElement(By.name("")).CSS Selector − This can be derived from element tags and attributes.Syntax −driver.findElement(By.cssSelector("")).xpath − This can be derived from element ... Read More

How to count the number of headers in a web table in Selenium?

Debomita Bhattacharjee

Debomita Bhattacharjee

Updated on 10-Jun-2020 12:39:18

626 Views

The total number of headers in the web table can be counted with the help of findElements() method. The logic is to return a list of web elements with xpath with the help of tag inside the table, then getting the size of that list.Code ImplementationExampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; ... Read More

How to count the total number of links in a page in Selenium?

Debomita Bhattacharjee

Debomita Bhattacharjee

Updated on 10-Jun-2020 12:37:42

11K+ Views

The total number of links in a page can be counted with the help of findElements() method. The logic is to return a list of web elements with tagname anchor, then getting the size of that list.Code ImplementationExampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public ... Read More

How to extract the text of a webelement in Selenium?

Debomita Bhattacharjee

Debomita Bhattacharjee

Updated on 10-Jun-2020 12:35:36

619 Views

Selenium extracts the text of a webelement with the help of getText() method.Code Implementation with getText().Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class ExtractText {    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ... Read More

Advertisements