selenium选错弹出层的下拉框

要先选中这个弹出层的form元素,再找下拉框

public void downSelectBox(){
        driver.get("https://www.imooc.com/user/setprofile");
        driver.findElement(By.className("pull-right")).click();
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //先获取弹出层的form表单
        WebElement formElement = driver.findElement(By.id("profile"));
        
        WebElement job = formElement.findElement(By.id("job"));
        Select downList = new Select(job);
        downList.selectByIndex(2);
        //downList.selectByValue("1");
        //downList.selectByVisibleText("学生");
        downList.selectByIndex(3);
        //这个只能取消多选下拉框
        //downList.deselectByIndex(3);
        List<WebElement> list = downList.getAllSelectedOptions();
        for(WebElement option : list){
            System.out.println(option.getText());
        }
        System.out.println(downList.getFirstSelectedOption().getText());
    }

 

posted on 2018-09-20 16:19  tarrying  阅读(390)  评论(0编辑  收藏  举报