基于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选择下拉框的某一个选项

相关文章:

  • 2022-01-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2022-01-20
  • 2021-11-09
猜你喜欢
  • 2022-12-23
  • 2021-11-09
  • 2018-06-22
  • 2022-03-01
  • 2021-07-12
  • 2021-11-09
相关资源
相似解决方案