我是靠谱客的博主 迷路篮球,最近开发中收集的这篇文章主要介绍基于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选择下拉框的某一个选项的全部内容,希望文章能够帮你解决基于java,selenium选择下拉框的某一个选项所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(36)

评论列表共有 0 条评论

立即
投稿
返回
顶部