When I click button submit on that page, it will window.open()
a new page with an alert.
Does someone know how to get the new page's alert text "got you ?"
Below is my code, but it does not work.
public static void main(String[] args) throws Exception{
System.setProperty("webdriver.chrome.driver","D:\\auto\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.yizhike.com.cn/chou/a.html");
String current = driver.getWindowHandle();
driver.findElement(By.id("submit")).click();
Set<String> handlers = driver.getWindowHandles();
for (String s : handlers){
if (!s.equals(current)){
driver = driver.switchTo().window(s);
String aa = driver.switchTo().alert().getText(); // **it will take endless time in here**
System.out.println(aa);
}
}
}
a.html:
<html>
<head>
<title>page a</title>
<script type="text/javascript">
function Wopen(){
window.open('b.html','_blank','width=600,height=400,top=100px,left=0px')
}
</script>
</head>
<body>
<input type="button" onClick="Wopen()" value="submit" id="submit"/>
</body>
</html>
b.html:
<html>
<head>
<title>page b</title>
<script type="text/javascript">
alert("got you!");
</script>
</head>
</html>