【发布时间】:2020-06-29 05:36:47
【问题描述】:
作为自动化的一部分,我正在尝试使用 selenium 登录到本地托管的网站。该页面提供 HTTP 基本身份验证弹出窗口,我使用以下代码发送凭据。但是,在使用调试器并逐步执行代码时,我发现 TimeOut 异常重复发生(在旁边标有注释的行处)。
详情
- 我在 Chrome 浏览器及其对应的 chrome WebDriver 上尝试了从 79.0 到最新 84.0 的所有版本,但似乎在所有情况下都会出现此异常。
- 操作系统 - Windows Server W2k12 虚拟机。 [在 Windows 10 上也试过]
- Python 3.8 版
代码
import time
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')
driver = webdriver.Chrome(chrome_options=options)
driver.maximize_window()
driver.get(url)
wait = WebDriverWait(driver, 10)
alert = wait.until(EC.alert_is_present()) # This line causes the time out exception
alert = driver.switch_to.alert
alert.send_keys('domain\username' + Keys.TAB + 'password')
alert.accept()
time.sleep(5)
注意:
- 由于内部页面中的错误,我无法使用
https://username:password@ipaddress:port格式通过 URL 发送凭据,因此这迫使我将上述 selenium 方法作为我唯一的选择。 - firefox对应代码运行良好(针对同一目标内部网站)
可能的预感
我想知道,我是否缺少新创建的 VM 上的任何包,这对于 chrome WebDriver 的工作至关重要。例如,Firefox Gecko 驱动程序需要 Visual Studio 可再发行组件才能工作。 chrome WebDriver 是否需要任何此类等效包?
【问题讨论】:
标签: python-3.x selenium selenium-webdriver selenium-chromedriver