现在任何人都可以帮助我更新代码
我试图通过以下代码切换到第三个子窗口,但我收到错误为"元素当前不可见,因此可能无法与"进行交互。 不确定出了什么问题
Set<String> set= driver.getWindowHandles();
//As set in not indexable collection; create iterator to access items(Strings) in set
Iterator<String> it=set.iterator();
//Use next() method of iterator to access elements one by one from set
String parentwin=it.next();
String childwin=it.next();
//Pass webdriver control to child window and click on Actions drop down and select "Sync Google Sheet" option.
driver.switchTo().window(childwin);
/*WebDriverWait wait= new WebDriverWait(driver,20);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(".//*[@id='products_ingested']/div[1]/div/div/div[2]/div/button")));*/
Thread.sleep(5000);
driver.findElement(By.xpath(".//*[@id='products_ingested']/div[1]/div/div/div[2]/div/button")).click();
driver.findElement(By.xpath(".//*[@id='products_ingested']/div[1]/div/div/div[2]/div/ul/li[2]/a")).click();
//New window will open; now pass control to this new window and perform operation on it.
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
Set<String> set1= driver.getWindowHandles();
Iterator<String> it1=set1.iterator();
String parentwin1=it1.next();
String childwin1=it1.next();
String childwin2=it1.next();
System.out.println(childwin1);
System.out.println(childwin2);
System.out.println(parentwin1);
//pass control to this third window
driver.switchTo().window(childwin2);
Thread.sleep(5000);
//Writing code to perform operations on this third window
Select sel = new Select(driver.findElement(By.id("spreadsheet_select")));
sel.selectByVisibleText("Test Sheet {AKASH.SRIVASTAVA}");
答案 0 :(得分:0)
以下代码将帮助您切换到子窗口:
String winHandleBefore = driver.getWindowHandle();
for (String winHandle : driver.getWindowHandles()) {
// Switch to child window
driver.switchTo().window(winHandle);
}
您还可以处理多个子窗口,Check here。
答案 1 :(得分:0)
现在,我可以处理第三个子窗口并对其进行操作。 问题在于我无法识别第三个子窗口元素。
答案 2 :(得分:0)
这是使用Java中的Set方法然后单击父窗口然后将控件传递给子窗口然后再次将控件传递给第二个子窗口以及我们可以遵循的系列来完成的。