我尝试将 ExplicitWait 用于自动提示框,但它不起作用,所以我使用简单Thread.sleep(5000)
:
/***************************************************************************************/
// The below Thread.sleep(5000) works fine
// Thread.sleep(5000);
// However the below Explicit Wait block does not recognize the element
WebDriverWait wait5000 = new WebDriverWait(driver, 0);
wait5000.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@class='auto_suggest']/*[@class='title_item']")));
/***************************************************************************************/
WebElement firstItem = driver.findElement(By.xpath("//*[@class='auto_suggest']/*[@class='title_item']"));
firstItem.click();
System.out.println("Done!");
}
}
我可以使用Thread.sleep(5000)
,但这效率不高,因为时间损失。有没有办法引入一个明确的等待自动建议框?如何更有效地点击自动提示框?