- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python + Selenium | How to locate elements in span class & not unique ID
We can locate elements in span class and not unique id with the help of the Selenium webdriver. We can identify an element having a class attribute with the help of the locator xpath, css or class name.
To locate elements with these locators we have to use the By.xpath, By.xpath or By.cssSelector method. Then pass the locator value as a parameter to this method.
Let us see the html code of a button having a span class and try to identify it.
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") l = driver.find_element_by_id("textemail") l.send_keys("firstname.lastname@example.org") #get value entered s = l.get_attribute('value') #identify element with span class m = driver.find_element_by_xpath("//span[@class='input_group_button']") #verify if element present b = m.is_displayed() if b: print("Element with span class available") else: print("Element with span class not available") #close browser driver.close()
- How to locate element by partial id match in Selenium?
- How to access unique Android device ID?
- Selenium and Python to find elements and text?
- How to get text found between span – Selenium
- How do we style HTML elements using the span tag <span>?
- How to locate descendant elements of a particular type of elements in jQuery?
- How to get unique elements in nested tuple in Python
- Plus One in Python
- How to locate a particular module in Python?
- How to select the text of a span on click in Selenium?
- Difference between an id and class in HTML
- How to get objects by ID, Class, Tag, and Attribute in jQuery?
- Unable to locate an element using xpath error in selenium-java
- How to add a unique id for an element in HTML?
- How to specify a unique id for an element in HTML?