简体   繁体   中英

How to deal with prompt alert for using Selenium Webdriver

I am using Selenium Webdriver to validate a specific site and upon going to the site, it prompts me to enter a username and password via a prompt window. i cannot right click it to inspect properties

Prompt Window Screenshot: 在此处输入图像描述

I already tried the driver.switchTo().alert() and the Webdriver Wait but it still wont work. tried both on Chrome and firefox browsers

public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","C:\\Users\\eclipse-workspace\\ChromeDemo\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver ();
        //Go to Website
driver.get("enter site here");
//After entering the site, Prompt window appears
driver.switchTo().alert();
driver.findElement(By.name("User Name:")).sendKeys("nUsername");
driver.findElement(By.name("Password:")).sendKeys("nPassword");

I expect that the prompt window will be populated with the username and password but it doesn't

Try accessing the URL with username and password in below format, this will not show you the alert url: http://username:password@siteURL

driver.get(url)

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