- 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 can I get the href of elements found by partial link text using Selenium?
We can get the href of elements found by partial link text with Selenium webdriver. First of all we need to identify the links with help of the find_elements_by_partial_link_text() method.
Next to get hold of href of the links we have to use the get_attribute() method and then pass href as a parameter to the method.
Let us identify the href attribute of links identified with partial link text Policy in the below page.
Example
from selenium import webdriver driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) driver.get("https://www.tutorialspoint.com/about/about_careers.htm") #identify links with partial link text l= driver.find_elements_by_partial_link_text("Policy") #iterate links for i in l: #get href from get_attribute() print("Href value of link: " + i.get_attribute("href")) driver.close()
Output
Advertisements