- 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 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
- Related Articles
- How to get text found between span – Selenium
- How to prevent text select outside HTML5 canvas on double-click?
- How to click on a link in Selenium?
- Using Selenium in Python to click/select a radio button.
- How to click on a link in Selenium with python?
- How to click on image in selenium webdriver Python?
- How to click on hidden element in Selenium WebDriver?
- How to click on a hyper link using linkText in Selenium?
- How to click on a link using Selenium webdriver in Python.
- How to perform double click on an element in Selenium?
- How to click on across browsers using Selenium Webdriver?
- How to click on a button with Javascript executor in Selenium with python?
- How to click on a link with a Javascript executor in Selenium with python?
- How to perform right click on an element with Actions in Selenium?
- How to perform double click on an element in Selenium with python?

Advertisements