您的位置:首页 > 编程语言 > Java开发

selenium自动化测试 java 选择 下拉列表 的一个选项

2017-10-16 17:07 681 查看
hmtl代码

    <select selected="selected" class="ordername" style="width:120px" name="User[user_type]" id="User_user_type">  

    <option value="0">Please Choose</option>  

    <option value="1" selected="selected">one</option>  

    <option value="2">Advertiser</option>  

    <option value="4">Agent</option>  
    </select> 

方法一:

   Select userSelect=new Select(driver.findElement(By.id("User_user_type")));  

   userSelect.selectByVisibleText("电子 数码");

方法二:

    WebElement adrOption=driver.findElement(By.cssSelector("#User_user_type option[value='2']"));  

    adrOption.click(); 

注意:

不在上述方法前加driver.findElement(By.id("User_user_type")).click();

否则只展开下拉列表,鼠标在”电子 数码“上,但是并不会点击此项。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java selenium 下拉列表