【发布时间】:2019-07-18 23:42:48
【问题描述】:
我正在尝试在 python 中使用 selenium 登录我的 Google 帐户。我不断遇到以下错误:
selenium.common.exceptions.ElementNotInteractableException: Message: Element <input class="whsOnd zHQkBf" name="password" type="password"> is not reachable by keyboard
我查看了其他一些类似的问题,但大多数都是关于身份验证失败的问题。另一个post 建议寻找覆盖它的东西,但我什么也没看到。此外,输入框不会根据其 html 隐藏:
<input type="password" class="whsOnd zHQkBf" jsname="YPqjbf" autocomplete="current-password" spellcheck="false" tabindex="0" aria-label="Enter your password" name="password" autocapitalize="off" dir="ltr" data-initial-dir="ltr" data-initial-value="" badinput="false">
我还尝试在访问密码输入框之前放置一些等待语句,但没有成功。 我还检查以确保 find_elemnt_by 函数只返回 1 个元素。
为了确保我做得正确,我在 Amazon 上对其进行了测试,它运行良好,所以不知道为什么 Google 会很困难。
这是我的代码:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# create a new Firefox session
driver = webdriver.Firefox(executable_path="D:\Selenium\geckodriver.exe")
driver.implicitly_wait(5)
# Navigate to youtube
driver.get("https://www.youtube.com/")
sign_in_button = driver.find_element_by_css_selector('ytd-button-renderer.style-scope:nth-child(5)')
sign_in_button.click()
username = driver.find_element_by_css_selector('#identifierId')
username.send_keys('johndoe@gmail.com')
next_button = driver.find_element_by_css_selector('#identifierNext')
next_button.click()
password_text_box = driver.find_element_by_css_selector('.I0VJ4d > div:nth-child(1) > input:nth-child(1)')
# FAILS HERE
password_text_box.send_keys('fakepassword')
next_password_button = driver.find_element_by_css_selector('#passwordNext')
next_password_button.click()
有什么建议吗?
【问题讨论】:
标签: python selenium selenium-webdriver selenium-firefoxdriver