How can I get the href of elements found by partial link text?

PythonSeleniumSelenium Chromedriver

Python Problem Overview


Using Selenium and the Chrome Driver I do:

links = browser.find_elements_by_partial_link_text('##') matches about 160 links.

If I try,

for link in links:
    print link.text

with it I get the text of all the links:

##1
##2
...
##160

The links are like this:

<a href="1.html">##1</a>
<a href="2.html">##2</a>
...
<a href="160.html">##160</a>

How can I get the href attribute of all the links found?

Python Solutions


Solution 1 - Python

Call get_attribute on each of the links you have found:

links = browser.find_elements_by_partial_link_text('##')
for link in links:
    print(link.get_attribute("href"))

Solution 2 - Python

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEduard FlorinescuView Question on Stackoverflow
Solution 1 - PythonScottView Answer on Stackoverflow
Solution 2 - Pythoneugene.polschikovView Answer on Stackoverflow