python selenium find_element_by_name

时间:2014-05-10 12:50:10

标签: python selenium

找到https://accounts.google.com/ServiceLogin?

的电子邮件输入的正确代码是什么

html为<input id="Email" class="" type="email" spellcheck="false" value="" placeholder="Email" name="Email"></input>

我引用了https://pypi.python.org/pypi/selenium

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('https://accounts.google.com/ServiceLogin?')

elem = browser.find_element_by_name()我试过了:

elem=browser.find_element_by_name('input id="Email"')
elem=browser.find_element_by_name('input id="Email" class="" type="email" spellcheck="false" value="" placeholder="Email" name="Email"')
elem=browser.find_element_by_name('input id="Email" class=""')
elem=browser.find_element_by_name('id="Email" class="" type="email" spellcheck="false" value="" placeholder="Email" name="Email"')
elem=browser.find_element_by_name('id="Email" class=""')

这些都不起作用。

2 个答案:

答案 0 :(得分:1)

试试这个:

elem=browser.find_element_by_name("Email")

find_element_by_name期望HTML中的name值。因此,对于name="Email",您需要find_element_by_name("Email")

答案 1 :(得分:0)

您也可以尝试使用标签的ID

elem = browser.find_element_by_id("Email")