
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
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()
Advertisements