【问题标题】:selenium - how to target a checkbox with a NAME and a VALUEselenium - 如何使用 NAME 和 VALUE 定位复选框
【发布时间】:2015-07-25 03:18:46
【问题描述】:

我有以下 HTML:

<div class="small-4 columns text-right">
    <input type="radio" value="false" name="auto_policy[autos_attributes][0][parked_at_mailing_address]" autocomplete="smartystreets"></input>
    <div class="radio_button_label"></div>
    <input type="radio" value="true" name="auto_policy[autos_attributes][0][parked_at_mailing_address]" checked="checked" autocomplete="smartystreets" style="background-color: rgb(255, 255, 255);"></input>
    <div class="radio_button_label"></div>
</div>

鉴于它们具有相同的名称,我如何定位“false”选项?

我试过了

css=a[name='auto_policy[add_violation]' value='false']

css=a[name='auto_policy[add_violation]', value='false']

但它“找不到”

一个可行的选择是使用

//input[@name='auto_policy[add_violation]'][2] 

但是我想避免[2] 看起来很脆弱并且能够使用 value='false' 代替

【问题讨论】:

  • 能否请您添加完整的 html 代码 sn-p,包括具有属性 auto_policy[add_violation]a 标签?

标签: css selenium css-selectors selenium-ide


【解决方案1】:

我会使用以下 CSS 选择器(而不是如何组合多个条件):

css=input[name*=add_violation][value=false]

*= 表示“包含”。

或者,一个 XPath 表达式:

xpath=//input[contains(@name, "add_violation") and @value="false"]

【讨论】:

  • 看起来不错,但即使稍微摆弄一下似乎也能找到元素。
  • @MichaelDurrant 哎呀,应该是input,而不是a - 已修复:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-18
  • 2018-04-13
  • 2014-02-08
相关资源
最近更新 更多