gpt4 book ai didi

java - 如何等待一定数量的行?

转载 作者:行者123 更新时间:2023-11-29 05:25:54 24 4
gpt4 key购买 nike

我正在测试一个网页,它的一些内容加载了 XMLHttpRequest .我需要检查我的 <table>在 Ajax 调用之后包含 2 行(因为页面在加载时已经包含 1 行)。

我的测试:

@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
driver.get("http://localhost/index.html");
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
}

@Test
public void testIfPartnerListPageIsPresent() {
driver.findElement(By.id("123")).click();
List<WebElement> rawList = driver.findElement(By.id("id-213"))
.findElements(By.tagName("tr"));
assertTrue("More than 1 raw", rawList.size() > 1);
}

我如何要求 Selenium 等待我表中的其他行?

最佳答案

此函数将等到表至少包含给定的行数

 public void waitUntilRowPopulates(WebElement element, final int rowCount) {
final WebElement table = element;

new FluentWait<WebDriver>(driver)
.withTimeout(60, TimeUnit.SECONDS)
.pollingEvery(10, TimeUnit.MILLISECONDS)
.until(new Predicate<WebDriver>() {

public boolean apply(WebDriver d) {
List<WebElement> rawList = table.findElements(By.tagName("tr"));
return (rawList.size() >= rowCount);
}
});
}

关于java - 如何等待一定数量的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22707284/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com