 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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 select the text of a span on click in Selenium?
We can select the text of a span on click with Selenium webdriver. To identify the element with span tag, we have to first identify it with any of the locators like xpath, css, class name or tagname.
After identification of the element, we can perform the click operation on it with the help of the click method. Then obtain its text with the text method. Let us investigate the html code of a webelement with a span tag.

Example
from selenium import webdriver #set chromodriver.exe path driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) #launch URL driver.get("https://www.tutorialspoint.com/index.htm") #identify element and enter text e = driver.find_element_by_class_name("search") e.send_keys("tutorialspoint@gmail.com") l = e.get_attribute('value') print("Text entered: ") print(l) #identify span element then click and obtain text s = driver.find_element_by_css_selector("span[class='input_group_button']") s.click() t = s.text print("Text of element with span: ") #quit browser driver.quit()  Output

Advertisements
 