Python Selenium 'WebElement' 对象没有属性 'Get_Attribute'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36476861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Selenium 'WebElement' object has no attribute 'Get_Attribute'
提问by Sapir
I'm using Selenium webdriver (chrome) with Python, I'm trying to get the hreffrom all the links on the webpage. When I try the following:
我在 Python 中使用 Selenium webdriver (chrome),我试图从网页上的所有链接中获取href。当我尝试以下操作时:
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:
它设法获取所有链接,但在 get_attribute 上出现错误:
'WebElement' object has no attribute 'Get_Attribute'
“WebElement”对象没有属性“Get_Attribute”
Though everywhere I looked it seems like it should work.
虽然我到处看它似乎应该工作。
回答by Florent B.
The "Get_Attribute" property doesn't exist, but the "get_attribute" property does:
“Get_Attribute” 属性不存在,但“get_attribute” 属性存在:
items = driver.find_elements_by_tag_name("a")
print items
for item in items:
href = item.get_attribute('href')
print href
回答by YHS
For python with input-field is like:
对于带有输入字段的python,就像:
nowText = driver.find_element_by_id("source").get_attribute("value")
print(nowText)
回答by Rkmr039
src = driver.find_element_by_css_selector("img").get_attribute("src")