如何在Selenium webdriver中等待iFrames完全加载?
我们可以使用Selenium webdriver等待iframe完全加载,首先我们需借助iframe id、名称、数字或webelement识别iframe。然后,我们将在同步中使用显式等待概念来等待iframe加载。
我们需要导入org.openqa.selenium.support.ui.ExpectedConditions 和 导入org.openqa.selenium.support.ui.WebDriverWait 来合并预期条件和WebDriverWait类。我们将用条件frameToBeAvailableAndSwitchToIt等待iframe加载。
让我们看看一个框架的html文档。

示例
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;
public class FrameLoadWait{
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS);
driver.get("https://the-internet.herokuapp.com/nested_frames");
// frame load explicit condition
WebDriverWait w = new WebDriverWait(driver, 5);
w.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("frame-bottom"));
// identify element inside frame
WebElement p=driver.findElement(By.cssSelector("body"));
System.out.println("Text inside frame is: " + p.getText());
driver.close();
}
}输出

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP