Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium 'WebElement' object has no attribute 'Get_Attribute'

I'm using Selenium webdriver (chrome) with Python, I'm trying to get the href from all the links on the webpage. When I try the following:

items = driver.find_elements_by_tag_name("a")
print items

for item in items:
    href = item.Get_Attribute('href')
    print href

It manages to get all the links, but on get_attribute I get an error:

'WebElement' object has no attribute 'Get_Attribute'

Though everywhere I looked it seems like it should work.

like image 318
Sapir Avatar asked Apr 07 '16 12:04

Sapir


3 Answers

The "Get_Attribute" property doesn't exist, but the "get_attribute" property does:

items = driver.find_elements_by_tag_name("a")
print items

for item in items:
    href = item.get_attribute('href')
    print href
like image 177
Florent B. Avatar answered Nov 20 '22 15:11

Florent B.


For python with input-field is like:

nowText = driver.find_element_by_id("source").get_attribute("value")
print(nowText)
like image 29
YHS Avatar answered Nov 20 '22 15:11

YHS


src = driver.find_element_by_css_selector("img").get_attribute("src")
like image 1
Rkmr039 Avatar answered Nov 20 '22 15:11

Rkmr039