- 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
Is there a way to find an element by attributes in Python Selenium?
We can find an element by attributes with Selenium webdriver. There are multiple ways to do this. We can use the locators like css and xpath that use attributes and its value to identify an element.
For css selector, theexpression to be used is tagname[attribute='value']. There are two types of xpath – absolute and relative. The xpath expression to be used is //tagname[@attribute='value'], the tagname in the expression is optional. If omitted, the xpath expression should be //*[@attribute='value'].
Let us consider an element with input tagname. It will be identified with xpath locator with id attribute (//input[@id='txtSearchText']).
from selenium import webdriver driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe") driver.implicitly_wait(0.5) driver.get("https://www.tutorialspoint.com/tutor_connect/index.php") #identify element with attribute id l= driver.find_element_by_xpath("//input[@id='txtSearchText']") l.send_keys("Tutorialspoint") #get_attribute() to get value of input box print("Enter text is: " + l.get_attribute('value')) driver.close()
- Is there any way to load an extension in chrome browser using Selenium Webdriver?
- Find and click element by title Python Selenium.
- Is there an easy way to rename a table in a MySQL procedure?
- Is there a way to list collections in MongoDB?
- Is there a way to name columns in an INSERT statement in MySQL?
- Find Element and FindElements by XPath in Selenium
- Is there any way to embed a PDF file into an HTML5 page?
- How to find a radio button element by value using Selenium?
- Is there a standard way of using exception chains in Python 3?
- Is there an elegant way of passing an object of parameters into a function?
- Is there a way to know your current username in MySQL?
- Is there a way to change the date format in php?
- Find div element by multiple class names in Selenium?