我写了个方法如下,如果页面不刷新,能成功捕获。所以能定位是因为页面刷新而抛的异常:
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;
}
}
}
return tip;
}
请救大神如果捕获这个提示框内容啊???~~~~~~~~~~~~困惑啊!作者: dgjy1978 时间: 2015-4-23 14:56
程序运行到 tip = div.getText()时报的错作者: zzhengjian 时间: 2015-4-28 22:46
页面刷新之后是要重新去find元素的,然后才可以操作,这是webdriver的机制。不然就是报你上面的错误,element not found in cache。