一尘不染

Python Selenium find_element_by_name

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=""')

这些都不起作用。


阅读 960

收藏
2020-06-26

共1个答案

一尘不染

试试这个:

elem=browser.find_element_by_name("Email")

find_element_by_name期望nameHTML行中的的值。所以在这种情况下name="Email",你会给find_element_by_name("Email")

2020-06-26