Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 323
user3787179 Avatar asked Jul 21 '18 01:07

user3787179


1 Answers

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
like image 175
Thomas Walpole Avatar answered Nov 03 '22 01:11

Thomas Walpole