Java WebDriverWait+;搜索项目
创建激活代码后,需要1-60秒才能将代码上载到系统中。所以在创建一个新代码之后,我想使用WebDriverWait 60秒,以确保在这段时间内每3秒我都要点击搜索按钮。有没有办法做到这一点Java WebDriverWait+;搜索项目,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,创建激活代码后,需要1-60秒才能将代码上载到系统中。所以在创建一个新代码之后,我想使用WebDriverWait 60秒,以确保在这段时间内每3秒我都要点击搜索按钮。有没有办法做到这一点 (new WebDriverWait(driver, 60)) .until(ExpectedConditions.textToBePresentInElement(By.xpath("//*[@id='searchResults']"), activationCode)); 为此,可以使用for循环。在循
(new WebDriverWait(driver, 60))
.until(ExpectedConditions.textToBePresentInElement(By.xpath("//*[@id='searchResults']"), activationCode));
为此,可以使用for循环。在循环中等待3秒钟,如果您的条件(代码生成)得到满足,则退出循环 通过这样做,如果代码是在10秒内生成的,您不需要等待60秒。您将在等待12秒后出来。这是通过
WebDriverWait
免费提供的
在创建WebDriverWait
时,您可以设置一个值,告诉它尝试运行代码的频率(单击搜索按钮):
,java.util.concurrent.TimeUnit)
所以只要将pollingEvery设置为三秒循环方法对我来说效果很好,谢谢h4k3r的建议
while(dynamicSearch(activationCode,"//*[@id='searchResults']") && key<20)
{
driver.findElement(By.xpath(".//*[@id='searchItem']")).click();
key++;
}
.until(ExpectedConditions.texttobepresentElement)(通过.xpath(XPathAddress),
激活肽)
返回false;
}
捕获(例外e){ 返回true; } 还有一个建议:) 在XPATH上使用CSS选择器,因为CSS选择器比XPATH更快
{ (new WebDriverWait(driver, 3))