`
jerome_wang
  • 浏览: 158734 次
  • 性别: Icon_minigender_1
  • 来自: 云南
社区版块
存档分类
最新评论

selenium-webdriver: element is not attached to the page问题解决

 
阅读更多

现象: 今天在遍历选择select option 时出现:element is not attached to the page document

原因:The reason was because javascript loaded the element one more time after i have referred so my date reference pointed to an unexisting object even if it was right their on UI

解决方案:select 为例

    private void selectOption(WebDriver driver,By by) {
        try{
           
            Select clsSelect = new Select(driver.findElement(by));
            List<WebElement> options = clsSelect.getOptions();   
            for(int e = r; e < options.size(); e++){
                if(options.get(e).isSelected()){
                    continue;
                }else{
                    clsSelect.selectByIndex(e);
                    r = e;
                }
            }
        }catch(StaleElementReferenceException e){
            selectOption(driver,by);
        }
   
    }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics