I am writing a simple Java code that uses Selenium ChromeDriver.
The flow is simple: The driver goes to a website --> find a HTML element and click it --> An authentication pop-up appears --> ...
But here the problem arises. The program could not continue after the click command, which is: "href.click()
".
I MANUALLY entered the username and password to the authentication pop-up, and the print command only works AFTER that.
Even if I do not provides the authentication, the print command should still be activated after the click command has finished. But, in this case, it doesn't.
Which means, the click command "href.click()
" only finishes when the authentication pop-up is already finished. But since the click is an atomic command, how and when am I supposed to enter the authentication details ?
I tried using an alert, or added any lines of codes AFTER the click line but none of them worked.
I also tried adding "driver.get("http://username:password@somesite.com/")
", but it doesn't work also.
public void site_header_is_on_home_page() {
System.setProperty("webdriver.chrome.driver", "...\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://somesite.com/");
WebElement href = driver.findElement(By.xpath("//a[@href='https://xyz.../']"));
href.click();
//Nothing works after this line.//
System.out.println("cccc");
}
The screen after the "driver.get("http://somesite.com/")" command
The screen after the click command. An authentication pop-up is issued