水豚:点击 <span> 内的文字
Capybara: click on text within <span>
我有一个可以申请 indeed.com 工作的机器人。它会收集工作,然后一项一项地申请。但是,最近确实使事情变得更加困难。过去只能找到按钮的 id 并使用它,但现在 id 是动态的:随着不同的工作职位而变化。
有谁知道如何 link 到 "Apply Now" 按钮(不是真正的按钮),如果下面的代码是:
<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>
点击该元素的方法有很多种,最简单的 3 种可能是
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
在我的例子中,我不得不 select 使用 iframe 中的 js-chosen
库显示的选项。所以,它不是常规的 select
标签。所以必须按照 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
我有一个可以申请 indeed.com 工作的机器人。它会收集工作,然后一项一项地申请。但是,最近确实使事情变得更加困难。过去只能找到按钮的 id 并使用它,但现在 id 是动态的:随着不同的工作职位而变化。
有谁知道如何 link 到 "Apply Now" 按钮(不是真正的按钮),如果下面的代码是:
<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>
点击该元素的方法有很多种,最简单的 3 种可能是
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
在我的例子中,我不得不 select 使用 iframe 中的 js-chosen
库显示的选项。所以,它不是常规的 select
标签。所以必须按照 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