Selenium 'WebElement' object has no attribute 'Get_Attribute'

 ̄綄美尐妖づ 提交于 2019-12-19 06:02:15

问题


I'm using Selenium webdriver (chrome) with Python, trying to get the href from all the links on the page. 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.

Any solutions?

Thanks!


回答1:


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



回答2:


For python with input-field is like:

nowText = driver.find_element_by_id("source").get_attribute("value")
print(nowText)



回答3:


src = driver.find_element_by_css_selector("img").get_attribute("src")


来源:https://stackoverflow.com/questions/36476861/selenium-webelement-object-has-no-attribute-get-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!