水豚:在<span>中单击文本

时间:2018-07-21 01:55:26

标签: ruby-on-rails xpath capybara

我有一个机器人,可以应用在true.com上。它将收集工作,然后一一应用于他们。但是,最近确实使事情变得更加困难。过去只能找到按钮的ID并使用它,但是现在ID是动态的:从不同的工作位置进行更改。

如果下面的代码为:

,有人知道如何链接到“立即申请”按钮(不是真正的botton)吗?

<a class="indeed-apply-button" href="javascript:void(0);" id="indeed-ia-1532137767182-0">
  <span class="indeed-apply-button-inner" id="indeed-ia-1532137767182-0inner">
    <span class="indeed-apply-button-label" id="indeed-ia-1532137767182-0label">Apply Now</span>
    <span class="indeed-apply-button-cm">
      <img src="https://d3fw5vlhllyvee.cloudfront.net/indeedapply/s/14096d1/check.png" style="border: 0px;">
    </span>
  </span>
</a>

2 个答案:

答案 0 :(得分:5)

许多方法可以单击该元素,最简单的三种可能是

click_link('Apply Now') # find link by partial text and click it
click_link(class: 'indeed-apply-button') # find and click link by class
find('span', text: 'Apply Now').click # find span by text and click in it

答案 1 :(得分:0)

就我而言,我必须选择使用iframe中的js-chosen库显示的选项。因此,它不是常规的select标签。因此必须执行以下选择:-

within_frame(find("#cci_form")) do
  find('#showing_listing_id_chosen').click
  find('[data-option-array-index="2"]').click
end

但是,使用

没有运气
find('.active-result[data-option-array-index="2"]').click

find('li[data-option-array-index="2"]').click