Java 切换回iframe selenium

Java 切换回iframe selenium,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我正面临一个问题,我不知道我会错在哪里: Thread.sleep(10000); String mainWindow = driver.getWindowHandle(); while(true) { try { wc.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@class='iff-campaign-container']/a")));

我正面临一个问题,我不知道我会错在哪里:

   Thread.sleep(10000);
    String mainWindow = driver.getWindowHandle();

    while(true) {
        try {
            wc.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@class='iff-campaign-container']/a")));
            driver.findElement(By.xpath("//*[@class='iff-campaign-container']/a")).click();
//Here on click , it open new window in new browser.
            for (String winHandle : driver.getWindowHandles()) {
                driver.switchTo().window(winHandle); 
            }
            driver.close();
            driver.switchTo().window(mainWindow);
            driver.switchTo().frame(0);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            break;
        }
    }
我的等待条件在第一次循环运行后失败。
我正在这样做,xpath在iframe中,并使用iframe,因为每次单击后都会添加新的webelement。

driver.switchTo().frame(0)行中
您正在将驱动程序的
TargetLocator
更改为
iframe
,它没有指定的
xpath
,因此等待条件失败

如果在
iframe
中没有执行任何操作,请将其删除。如果你在最后使用它,请切换回

driver.switchTo().frame(0);
// do stuff on the iframe
driver.switchTo().defaultContent();

只需在eclipse中调试代码,并查看它在何处导致问题。请在try块的最后一行使用break语句