我写了个方法如下,如果页面不刷新,能成功捕获。所以能定位是因为页面刷新而抛的异常:
rg.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
Command duration or timeout: 834 milliseconds
我的方法:
public String getDialogTips(WebDriver webDriver){
JavascriptExecutor javascriptExecutor = (JavascriptExecutor)webDriver;
String tip="";
while (true) {
long begin=System.currentTimeMillis();
WebElement div =(WebElement)javascriptExecutor.executeScript("return $('.aui_content').find('div').get(0);");
System.out.println("time=="+(System.currentTimeMillis()-begin));
if(div!=null){
tip = div.getText();
System.out.println("tip=="+tip);
if (tip.length() > 0) {
break;