Selenium-无法获取子窗口的窗口句柄
Selenium-无法获取子窗口的窗口句柄-请在下面查找我正在使用的代码Selenium-无法获取子窗口的窗口句柄,selenium,selenium-webdriver,Selenium,Selenium Webdriver,Selenium-无法获取子窗口的窗口句柄-请在下面查找我正在使用的代码 wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ADD_NEWLIST_HEAD15105-15079"))); driver.findElement(By.id("ADD_NEWLIST_HEAD15105-15079")).click(); String parentWindow = driver.getWindo
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ADD_NEWLIST_HEAD15105-15079")));
driver.findElement(By.id("ADD_NEWLIST_HEAD15105-15079")).click();
String parentWindow = driver.getWindowHandle();
Set<String> handles = driver.getWindowHandles();
for (String windowHandle : handles) {
if (!windowHandle.equals(parentWindow)) {
driver.switchTo().window(windowHandle);
WebElement selectComplex = driver.findElement(By.id("WPBN_TesterID"));
Select reqComplex = new Select(selectComplex);
reqComplex.getOptions();
reqComplex.selectByVisibleText(tester);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='WPBN_TestingEffort']")));
driver.findElement(By.xpath(".//*[@id='WPBN_TestingEffort']")).clear();
driver.findElement(By.xpath(".//*[@id='WPBN_TestingEffort']")).sendKeys(Tduration);
driver.findElement(By.id("SAVEUI_HEAD15105-15079")).click();
driver.switchTo().window(parentWindow);
}
}
wait.till(预期条件。元素的可视性(按.id(“添加新列表”\u HEAD15105-15079”));
driver.findElement(按.id(“添加新列表”标题15105-15079))。单击();
字符串parentWindow=driver.getWindowHandle();
Set handles=driver.getWindowHandles();
用于(字符串windowHandle:handles){
如果(!windowHandle.equals(parentWindow)){
driver.switchTo().window(windowHandle);
WebElement selectComplex=driver.findElement(By.id(“WPBN_TesterID”);
选择reqComplex=new Select(选择复杂);
reqComplex.getOptions();
要求复杂。选择可视文本(测试仪);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“./*[@id='WPBN\u TestingEffort']”));
findElement(By.xpath(“./*[@id='WPBN\u testingefort'])).clear();
findElement(By.xpath(“./*[@id='WPBN\u testingefort'])).sendKeys(Tduration);
driver.findElement(By.id(“SAVEUI_HEAD15105-15079”))。单击();
driver.switchTo().window(父窗口);
}
}
单击链接后,您需要等待新窗口加载。使用以下代码:
wait.until(ExpectedConditions.visibilityOfElementLocated(By
.id("ADD_NEWLIST_HEAD15105-15079")));
int prevWndCount = driver.getWindowHandles().size();
driver.findElement(By.id("ADD_NEWLIST_HEAD15105-15079")).click();
String parentWindow = driver.getWindowHandle();
final int currWndCount = prevWndCount;
try {
// Waits for 60 seconds
WebDriverWait wait = new WebDriverWait(driver, 60);
// Wait until expected condition (Window count increases) met
wait.until((ExpectedCondition<Boolean>) new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
// Return true if window count increases, else return false
return d.getWindowHandles().size() > currWndCount;
}
});
}
catch (Throwable waitForNewWindowException) {
System.out
.println("Exception while waiting for new window to appear : "
+ waitForNewWindowException.getMessage());
}
Set<String> handles = driver.getWindowHandles();
for (String windowHandle : handles) {
if (!windowHandle.equals(parentWindow)) {
driver.switchTo().window(windowHandle);
WebElement selectComplex = driver.findElement(By
.id("WPBN_TesterID"));
Select reqComplex = new Select(selectComplex);
reqComplex.getOptions();
reqComplex.selectByVisibleText(tester);
wait.until(ExpectedConditions.visibilityOfElementLocated(By
.xpath(".//*[@id='WPBN_TestingEffort']")));
driver.findElement(By.xpath(".//*[@id='WPBN_TestingEffort']"))
.clear();
driver.findElement(By.xpath(".//*[@id='WPBN_TestingEffort']"))
.sendKeys(Tduration);
driver.findElement(By.id("SAVEUI_HEAD15105-15079")).click();
driver.switchTo().window(parentWindow);
}
}
wait.until(预期条件)。元素的可见性(通过
.id(“添加新列表”标题15105-15079);
int prevWndCount=driver.getWindowHandles().size();
driver.findElement(按.id(“添加新列表”标题15105-15079))。单击();
字符串parentWindow=driver.getWindowHandle();
最终整数currWndCount=prevWndCount;
试一试{
//等待60秒
WebDriverWait wait=新的WebDriverWait(驱动程序,60);
//等待,直到满足预期条件(窗口计数增加)
等待.直到((ExpectedCondition)新的ExpectedCondition(){
公共布尔应用(WebDriver d){
//如果窗口计数增加,则返回true,否则返回false
返回d.getWindowHandles().size()>currWndCount;
}
});
}
捕获(可丢弃的waitForNewWindowException){
系统输出
.println(“等待新窗口出现时出现异常:”
+waitForNewWindowException.getMessage());
}
Set handles=driver.getWindowHandles();
用于(字符串windowHandle:handles){
如果(!windowHandle.equals(parentWindow)){
driver.switchTo().window(windowHandle);
WebElement selectComplex=driver.findElement(按
.id(“WPBN_TesterID”);
选择reqComplex=new Select(选择复杂);
reqComplex.getOptions();
要求复杂。选择可视文本(测试仪);
等待。直到(预期条件。找到的元素的可见性)(通过
.xpath(“./*[@id='WPBN_testingefort']”);
driver.findElement(By.xpath(“./*[@id='WPBN\u testingefort']))
.clear();
driver.findElement(By.xpath(“./*[@id='WPBN\u testingefort']))
.发送密钥(t持续时间);
driver.findElement(By.id(“SAVEUI_HEAD15105-15079”))。单击();
driver.switchTo().window(父窗口);
}
}
检查是否驱动程序.getWindowHandles().size()代码>返回整数>=2