http://uniquepig.iteye.com/blog/1568208
public static boolean waitPageRefresh(WebElement trigger) { int refreshTime = 0; boolean isRefresh = false; try { for (int i = 1; i < 60; i++) { refreshTime = i; trigger.getTagName(); Thread.sleep(1000); } } catch (StaleElementReferenceException e) { isRefresh = true; System.out.println("Page refresh time is:" + refreshTime + " seconds!"); return isRefresh; } catch (WebDriverException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Page didnt refresh in 60 seconds!"); return isRefresh; }}
说明: 从selenium 2.16开始 增加了StaleElementReferenceException异常。在页面元素进行刷新后,再次对此元素进行操作则会抛出这个异常。所以可以根据这个作为标识判断页面是否刷新。或者是否跳转到下一个页面。能灵活设定等待时间。并且能够统计刷新时间。