Debomita Bhattacharjee has Published 863 Articles

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

Debomita Bhattacharjee

Debomita Bhattacharjee

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

3K+ 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

1K+ 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

241 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

956 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

15K+ 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

818 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

How to reset or clear an edit box in Selenium?

Debomita Bhattacharjee

Debomita Bhattacharjee

Updated on 10-Jun-2020 12:30:20

1K+ Views

We can reset or clear an edit box in Selenium with the help of clear() method.Code Implementation with clear().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 ResetText {    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver",    "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       ... Read More

What are relative locators in Selenium 4.0?

Debomita Bhattacharjee

Debomita Bhattacharjee

Updated on 10-Jun-2020 12:28:12

585 Views

The relative or friendly locators in Selenium 4.0 are available with the tagname attribute of the element.above() - Webelement located above with respect to the specified element.Syntax −driver.findElement(withTagName(“”).above(element));below() - Webelement located below with respect to the specified element.Syntax −driver.findElement(withTagName(“”).below(element));toLeftof() - Webelement located to the left of the specified element.Syntax −driver.findElement(withTagName(“”).toLeftOf(element));toRightOf() ... Read More

What are the various important exceptions in Selenium?

Debomita Bhattacharjee

Debomita Bhattacharjee

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

270 Views

The various important exceptions in Selenium are listed below −TimeOutException − This exception is thrown if an action does not complete in a particular duration. If the page element does not load even after the waits.driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS) ; driver.get(“https://www.tutorialspoint.com/index.htm” );In the above program, an implicit wait of 15 seconds is ... Read More

What are the different cookies methods in Selenium?

Debomita Bhattacharjee

Debomita Bhattacharjee

Updated on 10-Jun-2020 12:24:12

478 Views

The different cookies method in Selenium are listed below −driver.manage().deleteAllCookies() − This removes all cookies.driver.manage().deleteCookie(Id) − This removes a particular cookie.driver.manage().deleteCookieNamed(CookieName) − This removes a particular cookie based on Name.driver.manage().getCookies() − This returns all the cookies.driver.manage().getCookieNamed(CookieName) − This returns a particular cookie based on Name.driver.manage().addCookie(Id) − This adds a particular ... Read More

Advertisements