user3787179
user3787179

Reputation: 233

Capybara: click on text within <span>

I had a bot that would apply on indeed.com jobs. It would collect jobs then apply to them one by one. However, indeed recently made things a lot harder. Used to be able to just locate the button's id and use that but now the id is dynamic: changes from different job positions.

Does anyone know how it is possible to link to the "Apply Now" button (not really a botton) if the code below is:

<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>

Upvotes: 13

Views: 14488

Answers (2)

Shiva
Shiva

Reputation: 12514

in my case I had to select an option shown using js-chosen library inside an iframe. So, its not a regular select tag. So had to do following to select:-

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

But, no luck using

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

or

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

Upvotes: 0

Thomas Walpole
Thomas Walpole

Reputation: 49870

Many ways to click that element, the 3 simplest would probably be

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

Upvotes: 29

Related Questions