作者:傻孩纸黄国帅哟 | 来源:互联网 | 2023-09-25 17:32
getWindowHandles()
可以正常工作,但是在调用之前,getWindowHandles()
您必须按照以下步骤诱使WebDriverwait :
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
WebDriver driver= new FirefoxDriver();
driver.get("https://www.facebook.com/");
String parent= driver.getWindowHandle();
System.out.println("Parent Window is"+parent);
driver.findElement(By.linkText("Data Policy")).click();
WebDriverWait wait = new WebDriverWait(driver,5);
wait.until(ExpectedConditions.numberOfWindowsToBe(2));
Set s1= driver.getWindowHandles();
for(String s2:s1)
{
if(!parent.equalsIgnoreCase(s2))
{
driver.switchTo().window(s2);
Thread.sleep(5000);
System.out.println(driver.getWindowHandle());
System.out.println("get title of window"+driver.getTitle());
}
}
控制台输出:
Parent Window is4294967297
4294967303
get title of windowData Policy