- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 use text() in xpath in Selenium with python?
We can create a customized xpath with the help of the visible text on the page. This is achieved with the help of text() method in xpath.
The text() finds the object with the exact text match on the page.
Syntax
driver.find_element_by_xpath("//input[text()='Selenium']")
It will search for elements with visible text 'Selenium' on the page.
Example
Code Implementation with text().
from selenium import webdriver #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke actual browser driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch the URL driver.get("https://www.tutorialspoint.com/index.htm") #to refresh the browser driver.refresh() # identifying the edit box with the help of text() in xpath driver.find_element_by_xpath("//*[text()='GATE Exams']").click() #to close the browser driver.close()
- Related Articles
- How to use regular expressions in xpath in Selenium with python?
- What is xpath in Selenium with python?
- How to identify nth element using xpath in Selenium with python?
- How to use xPath in Selenium WebDriver to grab SVG elements?
- How will you travel from child to parent with xpath in Selenium with python?
- How to use Selenium with Python?
- How to get text with selenium web driver in python?
- How to read a text file in Selenium with python?
- How to write a text file in Selenium with python?
- How to clear the text entered in Selenium with python?
- What are the differences between xpath and css in Selenium with python?
- How to use relative xpath for locating a web-element by particular Attribute in Selenium?
- How to use a click() method in Selenium with python?
- What is xpath in Selenium?
- How to use regular expressions in css in Selenium with python?

Advertisements