【问题标题】:Select a radio button with Selenium in Firefox version 27在 Firefox 版本 27 中选择带有 Selenium 的单选按钮
【发布时间】:2014-07-24 11:30:27
【问题描述】:

我编写了 Selenium 测试来选择单选按钮。以下是“查看源代码”中的 html 和代码

//HTML 源代码

<b>
<font size="2" face="Arial, Helvetica, sans-serif">
<input type="radio" checked="" value="roundtrip" name="tripType"/>
Round Trip                  
<input type="radio" value="oneway" name="tripType"/>
One Way
</font>
</b>

//选择单选按钮的代码

List<WebElement> radios = wb.findElements(By.xpath("//input[@name='tripType']"));
radios.get(1).click();

以上代码不适用于 Firefox 版本。 27. 无论我们在 get() 函数中发送什么参数,它总是用于选择第一个单选按钮。但它在 IE 和 Chrome 中运行良好。后来我将Firefox升级到ver.31,然后它开始工作了。很想知道原因。谢谢。

【问题讨论】:

  • 用 Firefox 27 和 Firefox 31 打开页面时 HTML 源代码是否完全相同?
  • 是的,完全一样。

标签: selenium-webdriver


【解决方案1】:

尝试radios[0].click() 而不是radios.get(1).click()

【讨论】:

    猜你喜欢
    • 2017-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-30
    • 2015-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多