我是靠谱客的博主 失眠小丸子,最近开发中收集的这篇文章主要介绍用java选择selenium下拉选择框的一个选项,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

用selenium 选择select下的option

<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("Advertiser");
或者
WebElement adrOption=driver.findElement(By.cssSelector("#User_user_type option[value='2']"));
adrOption.click();

但是注意不要在上面的语句前加driver.findElement(By.id("User_user_type")).click();

不然就会只展开下拉列表,鼠标在Advertise上,但是并不会选中。一直处于这个状态


还有一些其他方法,可参考下面的链接

http://sqa.stackexchange.com/questions/12029/how-do-i-work-with-dropdowns-in-selenium-webdriver

最后

以上就是失眠小丸子为你收集整理的用java选择selenium下拉选择框的一个选项的全部内容,希望文章能够帮你解决用java选择selenium下拉选择框的一个选项所遇到的程序开发问题。

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

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

评论列表共有 0 条评论

立即
投稿
返回
顶部