1

Tried extracting the href from:

<a lang="en" class="new class" href="/abc/stack.com" 
tabindex="-1" data-type="itemTitles"><span><mark>Scott</mark>, CC042<br></span></a>

using elems = driver.find_elements_by_css_selector(".new class [href]") , but doesn't seem to work.

Also tried Python Selenium - get href value, but it returned an empty list.

So I want to extract all the href elements of class = "new class" as mentioned above and append them in a list

Thanks!!

pc_pyr
  • 562
  • 5
  • 20

2 Answers2

2

Use .get_attribute('href').

by_css_selector:

elems = driver.find_elements_by_css_selector('.new.class')
for elem in elems:
    print(elem.get_attribute('href'))

Or by_xpath:

elems = driver.find_elements_by_xpath('//a[@class="new class"]')
frianH
  • 7,295
  • 6
  • 20
  • 45
0

Just change it to

elems = driver.find_elements_by_css_selector(".new.class[href]")

OR

elems = driver.find_elements_by_css_selector("[class='new class'][href]")
KunduK
  • 32,888
  • 5
  • 17
  • 41