0
votes

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: enter image description here

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

1
Pretty sure you have to use the actual object returned by the switch like: Alert alert = driver.switchTo().alert();. This should contain some of the stuff you'd need to interact with the Alertmartijn p
Yes, I agree, use this: alert.authenticateUsing(new UserAndPassword(username, password));ou_ryperd
@ou_ryperd the authenticateUsing is undefined by the alert typeThat Guy
Oh, yes. That was removed after Selenium 3.14ou_ryperd
@ou_ryperd so heres what i did driver.get("http://" + "username" + ":" + "password" + "@" + "test.net"); But upon running it, it opened the browser and logged in successfully but after that, the link test.net is not appearing in the browser complete, the browser has http//test.net which is why it makes it "The site cant be reached"That Guy

1 Answers

1
votes

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)