创建激活代码后,需要1-60秒才能将代码上载到系统中。因此,在创建新代码之后,我想使用WebDriverWait 60秒来确保,在这个时间段内,每3秒我想点击Search。有办法这样做吗?
(new WebDriverWait(driver, 60))
.until(ExpectedConditions.textToBePresentInElement(By.xpath("//*[@id='searchResults']"), activationCode));发布于 2014-05-02 08:31:55
这是WebDriverWait提供的“免费”。
在创建WebDriverWait时可以设置一个值,告诉它应该多久运行一次代码(单击“搜索”按钮):
http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/ui/FluentWait.html#pollingEvery(long,java.util.concurrent.TimeUnit)
所以,将pollingEvery设置为等于3秒。
发布于 2014-05-02 05:50:46
您可以将for循环用于此目的。在循环中等待3秒,如果满足了条件(代码生成),则退出循环。
通过这样做,如果在10秒内生成代码,则不需要等待60秒。等了12秒你就出来了。
发布于 2014-05-02 15:52:12
循环方法对我很好,谢谢您的建议h4k3r。
while(dynamicSearch(activationCode,"//*[@id='searchResults']") && key<20)
{
driver.findElement(By.xpath(".//*[@id='searchItem']")).click();
key++;
}这是方法部分。
公共静态布尔dynamicSearch(String activationCode,String xpathAdress) {尝试 {(新WebDriverWait(驱动程序,3)) ( .until(ExpectedConditions.textToBePresentInElement(By.xpath(xpathAdress),activationCode); 返回false;} catch (异常e) {返回true;}
https://stackoverflow.com/questions/23418004
复制相似问题