基于java,selenium选择下拉框的某一个选项

基于java,selenium选择下拉框的某一个选项

//打印出所有选项值

        Select sel = new Select(driver1.findElement(ById.xpath(".//*[@id='GangManId']")));
        List<WebElement> options = sel.getOptions();
        for (WebElement option : options) {
            System.out.println(option.getText()); //Prints "Option", followed by "Not Option"
        } 

//使用name值选中
        WebElement mySelectElm = driver1.findElement(By.id("GangManId")); 
        Select mySelect= new Select(mySelectElm);
        mySelect.selectByVisibleText("于庆洋");

//使用value值选中

WebElement mySelectElm = driver1.findElement(By.id("GangManId")); 
        Select mySelect= new Select(mySelectElm);
        mySelect.selectByValue("10");基于java,selenium选择下拉框的某一个选项