Python 自动化无聊的东西-第11章-填写和提交表格p。259

Python 自动化无聊的东西-第11章-填写和提交表格p。259,python,selenium,Python,Selenium,我正试图运行代码登录gmail.com,但登录过程似乎已经改变。我已按如下方式修改了代码,但不断出现以下错误:selenium.common.exceptions.NoSuchElementException:Message:无法定位元素:{“method”:“id”,“selector”:“Passwd”} 有人看到或知道我做错了什么吗。谢谢 from selenium import webdriver browser = webdriver.Firefox() browser.get('ht

我正试图运行代码登录gmail.com,但登录过程似乎已经改变。我已按如下方式修改了代码,但不断出现以下错误:selenium.common.exceptions.NoSuchElementException:Message:无法定位元素:{“method”:“id”,“selector”:“Passwd”} 有人看到或知道我做错了什么吗。谢谢

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://gmail.com')
emailElem = browser.find_element_by_id('Email')
emailElem.send_keys('some_email@gmail.com')
nextElem = browser.find_element_by_id('next')
nextElem.click()                # click the button
passwordElem = browser.find_element_by_id('Passwd')
passwordElem.send_keys('password')
passwordElem.submit()
您需要使用
id=“Passwd”
查看是否存在元素:

您需要使用
id=“Passwd”
查看是否存在元素:


用于Python的稳定Gmail API:用于Python的稳定Gmail API:对我的代码进行以下修改后,它就可以工作了。谢谢你。wait=WebDriverWait(browser,10)对我的代码进行以下修改后,它就可以工作了。谢谢你。wait=WebDriverWait(浏览器,10)
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(browser, 10)
passwordElem = wait.until(EC.presence_of_element_located((By.ID, "Passwd")))
passwordElem.send_keys('password')
passwordElem.submit()