WebDriver/StaleElementException

来源:互联网 发布:nba2k15mc捏脸数据 编辑:程序博客网 时间:2024/06/05 07:59

使用WebDriver,在页面发生click()或刷新后,之前获取的元素失效。


解决方法:

public boolean retryingFindClick(By by) {        boolean result = false;        int attempts = 0;        while(attempts < 2) {            try {                driver.findElement(by).click();                result = true;                break;            } catch(StaleElementException e) {            }            attempts++;        }        return result;}
判断元素可以获取后,再重新获取。


0 0