- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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.
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("firstname.lastname@example.org") 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()
- 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 perform right click on an element with Actions in Selenium?
- How to perform double click on an element in Selenium with python?