页面加载后,我想等待几分钟,然后单击某个按钮。 试图做这样的事情:
{
"query": {
"bool": {
"should": [
{
"exists": {
"field": "market"
}
},
{
"bool": {
"must_not": [
{
"exists": {
"field": "market"
}
}
]
}
}
]
}
}
}
但是它不起作用。测试仍然可以执行,而无需等待几分钟。我错过了什么吗?
答案 0 :(得分:0)
Thread.Sleep()
在这里被评论了吗?
如果要始终等待几分钟,则需要使用显式等待-Thread.Sleep(50000));
或Thread.Sleep(TimeSpan.FromSeconds(5));
隐式等待通常在等待元素存在的上下文中使用。但是由于您总是想等待几分钟,因此应该使用显式等待。
答案 1 :(得分:0)
您可以结合使用WebDriverWait
和ExpectedConditions
来实现,然后利用.elementToBeClickable
方法,它将首先等待,然后单击。
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("...."))).click();
正在导入:
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.By;
10
超时(以秒为单位),然后尝试使用您的定位器更改By.xpath("....")
。