

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to identify elements based on text visible on page in Selenium?
To identify elements based on text visible on page, text() method is used in xpath.
Syntax −
driver.findElement(By.xpath("//tagname[text()=’value’]"))
Example
import 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 ChromeDriver(); String url = "https://www.tutorialspoint.com/index.htm"; driver.get(url); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); //xpath with text() method driver.findElement(By.xpath("//*[text()=’GATE Exams’]")).click(); driver.close(); } }
- Related Questions & Answers
- Finding text on page with Selenium 2
- How to perform scrolling action on page in Selenium?
- How to find the text visible on the button with JavaScript?
- JavaScript code to de-select text on HTML page.
- How to check if an image is displayed on page using Selenium?
- How to add Visible On click Button in HTML Code ?
- JavaScript: How to loop through all DOM elements on a page and display result on console?
- How to select the text of a span on click in Selenium?
- What to press ctrl +f on a page in Selenium with python?
- What to press ctrl +c on a page in Selenium with python?
- How to identify the elements by partially comparing to its attributes in Selenium?
- C# Program to filter array elements based on a predicate
- How to identify multiple elements at the same time in Selenium with python?
- How to get the total number of radio buttons on a page using Selenium?
- How to sort a vector in R based on manual position of elements?
Advertisements