
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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 element using XPATH syntax on Selenium for Python?
We can select elements using xpath with Selenium webdriver. Xpath is one of the most important locators. There are two types of xpath. They are known as absolute [starting from parent node in DOM] and relative xpath [starting from anywhere in DOM].
The xpath syntax is − //tagname[@attribute='value'] or //*[@attribute='value'].
Let us consider the html code of an element that we shall identify with the help of xpath−
The xpath expression is //input[@name='firstname'] or //*[@name='firstname'].
Example
from selenium import webdriver driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe") driver.implicitly_wait(0.5) driver.get("https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm") // identify element with xpath l = driver.find_element_by_xpath("//input[@name='firstname']") l.send_keys("Python") driver.quit()
Output
- Related Questions & Answers
- How to identify nth element using xpath in Selenium with python?
- The xpath of the element keeps changing, how do I find dynamic xpath for this element in Selenium
- How to find an element using the “XPath” in Selenium?
- Unable to locate an element using xpath error in selenium-java
- Clicking on elements within an SVG using XPath (Selenium WebDriver).
- Find Element and FindElements by XPath in Selenium
- How to use relative xpath for locating a web-element by particular Attribute in Selenium?
- How to select specified node within Xpath node sets by index with Selenium?
- How to identify the nth sub element using xpath?
- How to use text() in xpath in Selenium with python?
- What is xpath in Selenium with python?
- Select iframe using Python and Selenium
- How to use regular expressions in xpath in Selenium with python?
- Select parent element of known element in Selenium.
- What is xpath in Selenium?
Advertisements