【问题标题】:Selecting radio button when labels are not set in CSS using xpath locator使用 xpath 定位器在 CSS 中未设置标签时选择单选按钮
【发布时间】:2016-05-13 17:15:54
【问题描述】:

robotframework 中使用xpath 定位器,无法使用ride(机器人框架)为下面的HTML 标签选择单选按钮。

<Pre>    
    <div class="controls">
      <input checked="checked" data-val="true" data-val-required="The isPdfFormat field is required." id="isPdfFormat" name="isPdfFormat" value="true" type="radio"></input> PDF 
      <input checked="checked" id="isPdfFormat" name="isPdfFormat" value="false" type="radio"></input> CSV    
    </div>
</Pre>

【问题讨论】:

  • 哪个单选按钮?第一还是第二? xpath 可以用来这样做。
  • 第二个?你能不能给我同样的X-path。让我知道 xpath=//input[@id='isPdfFormat'][contains(text(),'CSV')] 是否有效。

标签: html xpath automated-tests robotframework


【解决方案1】:

请检查以下xpath
//input[normalize-space(following-sibling::text())='CSV' and @id='isPdfFormat']

【讨论】:

    【解决方案2】:

    您可以使用此 Xpath 选择第一个单选按钮

    (.//*[@class='controls']/input)[1]
    

    如果你想选择第二个使用这个

    (.//*[@class='controls']/input)[2]
    

    如果类不是唯一的并且匹配类的元素较多,请尝试使用Id

    (.//*[@id='isPdfFormat'])[1]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-06
      • 1970-01-01
      • 1970-01-01
      • 2020-09-27
      相关资源
      最近更新 更多