- Trending Categories
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 to get an attribute value from a href link in selenium?
We can get an attribute value from a href link in Selenium. To begin with, we have to first identify the element having an anchor tag with the help of any of the locators like css, id, class, and so on.
Next, we shall use the getAttribute method and pass href as a parameter to the method. Let us investigate an element with an anchor tag having the href attribute. Here, the value of href should contain /about/about_team.htm.
Example
Code Implementation.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class HrefValue{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get("https://www.tutorialspoint.com/about/about_team.htm"); // identify element WebElement l = driver.findElement(By.linkText("Team")); // href value from getAttribute() String v = l.getAttribute("href"); System.out.println("Href value of link: "+ v); driver.close(); } }
Output
- Related Articles
- How to search the value of the href attribute of a link in JavaScript?
- How to get an attribute value of an element in Selenium Webdriver?
- How to find the href attribute of a link in a document in JavaScript?
- How to click a link whose href has a certain substring in Selenium?
- How to effectively hide Href From a Link in PHP?
- Fetch all href link using selenium in python.
- How to get the value of the id attribute a link in JavaScript?
- How to get attribute of element from Selenium?
- How can I get the href of elements found by partial link text using Selenium?
- How to get the value of the hreflang attribute of a link in JavaScript?
- How to get the value of the rel attribute of a link in JavaScript?
- How to get the value of the target attribute of a link in JavaScript?
- How to get the value of the type attribute of a link in JavaScript?
- How to disable a href link in CSS?
- How to get an attribute value in jQuery?

Advertisements