简体   繁体   中英

How to handle authentication popup with Selenium WebDriver using python?

In this question an answer is given on how to handle authentication popup with Selenium WebDriver using Java . Now, can this be used also for python? It looks like the python driver has no class UserAndPassword like the Java pendant has.

Here is what I have tried:

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

Indeed there is no such class in python selenium library, but you can easly navigate to given alert and input user and password using other means.

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()

This will work on standard authentication, if it is custom made one you will probably have tinker with it abit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM