【发布时间】:2019-05-18 14:22:35
【问题描述】:
我正在尝试使用 python 和 selenium 从https://voice.google.com/about 自动发送短信。当我在下面运行代码时,它会选择谷歌浏览器的最新版本/实例并且工作正常。但是,当我运行它的无头模式时,它使用的是旧版本的谷歌浏览器(从截图中猜测)并给出TimeoutException() 异常。登录失败。
我在 IE 模拟器中检查了登录框的元素 id,它似乎是相同的。
url = "https://voice.google.com/about"
driver.get(url)
time.sleep(5)
driver.get_screenshot_as_file('C:\\Drivers\\Q11-0.png')
# Click on a GET GOOGLE VOICE
WebDriverWait(driver, 60).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="heroToggle"]/button/span'))).click()
print("Clicked on a get google voice")
# Click on a WEB
WebDriverWait(driver, 60).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="heroToggle"]/div/button[3]'))).click()
print("Clicked on a WEB button.")
driver.get_screenshot_as_file('C:\\Drivers\\Q11-1.png')
# Enter username and password
# THIS IS WHERE IT FAILS
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.ID, 'identifierId')))
email = driver.find_element_by_id('identifierId')
time.sleep(10)
email.send_keys('username')
time.sleep(10)
nextBtn = driver.find_element_by_xpath('//*[@id="identifierNext"]/content/span')
nextBtn.click()
driver.get_screenshot_as_file('C:\\Drivers\\Q11-2.png')
# Enter password
password = driver.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input')
password.send_keys('password')
nextBtn = driver.find_element_by_xpath('//*[@id="passwordNext"]/content')
nextBtn.click()
驱动程序已正确更新。 我不确定我做错了什么。任何帮助将不胜感激。
【问题讨论】:
-
使用无头浏览器时,代理足迹包含指示这是无头浏览器的标签。谷歌可以检测到这一点并为您提供不同版本的网站?你是如何确认它使用的是旧的 chrome 版本?
-
@Infern0,来自屏幕截图。我只是猜测。
-
@Infern0 ...代理足迹包含指示这是无头浏览器的标记。 Google 可以检测到这一点并为您提供不同版本的网站... 源/文档?
-
@DebanjanB 我在句尾放了一个问号。
-
@PRK 你谈到了选择最新版本/实例和无头模式,它使用的是旧版本的谷歌浏览器,但你没有' t 向我们展示了驱动程序的初始化。
标签: python-2.7 selenium selenium-chromedriver google-voice