简体   繁体   中英

How to Handle Browser Authentication popup using Selenium Webdriver

driver=new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://52.19.191.249/aur/");
driver.switchTo().alert().sendKeys("username");
driver.switchTo().alert().sendKeys("password");
driver.switchTo().alert().accept();

Getting message as no alert open

Since driver.switchTo().alert() doesn't wait for alert loaded, you need to wait for it. See https://stackoverflow.com/a/12639803/8609512

PS You can check it by adding a Thread.sleep(2000); for example, before driver.switchTo().alert().sendKeys("username"); sentence -- sleeps are usually a bad practice for test automation, but sometimes it could be helpful in debugging.

尝试使用此语法并运行 driver.get(" http://Username:password@52.19.191.249/aur/ ") ;

Try using autoit: [its simple and effective]

The code goes something like ::

from selenium import webdriver
import autoit
driver= webdriver.Chrome()
driver.get("http://sitewithpopup.com")
autoit.win_wait_active("",30) 
autoit.send("Username{TAB}")
autoit.send("Password{Enter}")

Since the autoit will and by default the cursor is on the field so you can make use of it.并且默认情况下光标位于字段上,因此您可以使用它。

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