如何切换到页面上的顺序 iframe
How to switch to sequential iframes on the page
我有一个场景,我需要在动态变化的 iframe 中单击一个图像。我只能点击页面上的第一张图片。该脚本之后无法识别 iframe,并给我 TimeoutException。下面是我的脚本:
//get the First iframe
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//iframe[contains(@id, 'adnxs_tag_')]")));
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@id, 'adnxs_tag_')]")));
然后我切换到页面上的下一个iframe
//get the second iframe
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//iframe[contains(@id, '336')]")));
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@id, '336')]")));
在切换到下一帧之前,您需要切换到默认内容:
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@id, 'adnxs_tag_')]")));
driver.switchTo().defaultContent();
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@id, '336')]")));
我有一个场景,我需要在动态变化的 iframe 中单击一个图像。我只能点击页面上的第一张图片。该脚本之后无法识别 iframe,并给我 TimeoutException。下面是我的脚本:
//get the First iframe
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//iframe[contains(@id, 'adnxs_tag_')]")));
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@id, 'adnxs_tag_')]")));
然后我切换到页面上的下一个iframe
//get the second iframe
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//iframe[contains(@id, '336')]")));
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@id, '336')]")));
在切换到下一帧之前,您需要切换到默认内容:
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@id, 'adnxs_tag_')]")));
driver.switchTo().defaultContent();
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@id, '336')]")));