如何使用python处理Selenium WebDriver的身份验证弹出窗口?

时间:2016-07-05 15:05:16

标签: java python selenium

this question中,给出了如何使用 Java 使用Selenium WebDriver处理身份验证弹出窗口的答案。现在,这可以用于python吗?看起来python驱动程序没有Java挂件那样的类UserAndPassword

以下是我的尝试:

    wait = WebDriverWait(driver, 10)
    alert = wait.until(ExpectedConditions.alertIsPresent())
    alert.authenticateUsing(UserAndPassword("user","passwd"))

1 个答案:

答案 0 :(得分:0)

确实python selenium库中没有这样的类,但您可以轻松导航到给定警报并使用其他方式输入用户和密码。

wait = WebDriverWait(driver, 10)
alert = wait.until(ExpectedConditions.alert_is_present())
alert = driver.switch_to_alert()
alert.send_keys('username')
alert.send_keys(Keys.TAB)
alert.send_keys('password')
alert.accept()

这将适用于标准身份验证,如果是自定义身份验证,您可能会对其进行修改。