- 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 the content of href within some targeted class using selenium?
We can get the content of href within some targeted class with Selenium webdriver. First of all we have to locate the element with an anchor tag having a specific class attribute value with the help of locators like xpath, css or classname.
Then we have to take the help of getAttribute method and pass href as an argument to the method. Let us have a look at the html code of an element with an anchor tag having the class and href attribute. The href value of the element should be /account/register?hl=en.
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 HrefVal{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("https://secure.indeed.com/account/login"); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); // identify element with specific class value WebElement m= driver.findElement(By.className("login-registrationBoldLink")); // getAttribute() to href value String val = m.getAttribute("href"); System.out.println("Href value of targeted: "+ val); driver.close() } }
Output
- Related Articles
- How to get content of entire page using Selenium?
- How to get css class name using Selenium?
- How can I get the href of elements found by partial link text using Selenium?
- How to get an attribute value from a href link in selenium?
- How to get the value of div content using jQuery?
- How to get the content of a textarea using jQuery?
- Fetch all href link using selenium in python.
- How to get HTML content of an element using jQuery?
- How to capture tooltip in Selenium using Actions Class?
- How to get the text from a website using selenium?
- How to add Flash content within a webpage in HTML?
- JavaScript - Get href value
- How to get the hash part of the href attribute of an area in JavaScript?
- How to find an element using the attribute “class name” in Selenium?
- How to get screenshot of full webpage using Selenium and Java?

Advertisements