Reputation: 1088
I have a div tag in which a tag is enclosed.
How can i get the value href
?
For example, "https://www.tweeter.com/rkShukl" from <a>
tag:
<a href="https://www.tweeter.com/rkShukl"></a>
Upvotes: 2
Views: 15845
Reputation: 11
alecxe is correct just one correction I had to do when using it was instead of
element.getAttribute('href');
I had to use double quotes for Java. It was assuming it was a character literal.
WebElement element = driver.findElement(By.id('id_of_the_link'));
element.getAttribute("href");
Upvotes: 1
Reputation: 474171
It depends on the language bindings. In java it is getAttribute()
:
WebElement element = driver.findElement(By.id('id_of_the_link'));
element.getAttribute('href');
In Python it is get_attribute()
:
element = driver.find_element_by_id('id_of_the_link')
element.get_attribute('href')
Upvotes: 8