我有一种情况,需要在动态更改的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')]")));
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句