【问题标题】:watir webdriver cannot select checkbox input elementwatir webdriver 无法选择复选框输入元素
【发布时间】:2016-08-09 23:43:40
【问题描述】:

如何编写这个查找元素语句以在 Watir Webdriver 中运行?

driver.find_element(:xpath, "//input[contains(@id,'sv')]")

CSS Selector:   #sincro_old > section:nth-child(1) > section:nth-child(1) > div:nth-child(2) > nav:nth-child(1) > fieldset:nth-child(3) > section:nth-child(2) > ul:nth-child(1) > li:nth-child(23) > input:nth-child(1)

请,非常感谢任何建议。

正在尝试识别能够选中复选框的元素。

REF:“watir webdriver 无法选择复选框输入元素”

<li class="langlist-item">
        <input type="checkbox" id="sv" data-js-id-lang="27" class="form-checkbox form-checkbox--inline">
        <label for="sv" class="langlist-label" title="Svenska">
        <svg class="icon langlist-icon icon--inline icon--xs" role="img">
            <use xlink:href="https://www.bigbuy.eu/public/img/icons/svg-defs.svg#icon-sv"/>
        </svg>
        Svenska    </label>
</li>[enter image description here][1]

【问题讨论】:

  • 您能否提供相关的 html 来复制您的问题?如果超时:b.checkbox(:id =&gt; 'sv').when_present.set,则表示它在页面上不可见。知道原因会很有用。
  • 这是否是要提供的相关 html:
  • 我一直在尝试使用 CSS 选择器,但到目前为止还没有任何效果。
  • 如何使用这个 CSS 选择器代码发布屏幕截图?
  • @LiterateAspects,您可以在问题中发布这些内容。编辑它以包含相关细节,而不是添加 cmets(因为它们很难理解)。

标签: checkbox webdriver watir


【解决方案1】:

driver.find_element(:xpath, "//input[contains(@id,'sv')]") 的确切等价物是:

browser.element(:xpath, "//input[contains(@id,'sv')]")

等效但更类似于 Watir 的语法将使用带有正则表达式的 :id 定位器(用于部分文本匹配):

browser.input(id: /sv/)

鉴于元素是一个复选框并且 id 看起来不是动态的,这样做会更有意义:

browser.checkbox(id: 'sv')

【讨论】:

  • 解决方案,来自 Justin Ko 2012 年的一篇帖子。如果有人寻求,这里是我挑战的解决方案:@@browser.li(:class=> 'dir', :text => /BS/).checkbox.set from [我建议改用可见元素。我认为它更容易阅读测试并且看起来更稳定。] [1] [1]:stackoverflow.com/questions/10822063/…
猜你喜欢
  • 2017-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-15
  • 2020-04-25
  • 1970-01-01
相关资源
最近更新 更多