Search code examples
ruby-on-railsweb-scrapingcapybarascraper

Capybara: click_button with no text or id?


Here is the html code:

<button type="button" class="icl-Button--transparent icl-Button--sm ia-AddCoverLetter-button"><span class="icl-ButtonIcon"><svg aria-label="Add cover letter" class="icl-Icon icl-Icon--blue icl-Icon--sm" role="img"><g><path d="M9.75,5.25H8.25v3h-3v1.5h3v3h1.5v-3h3V8.25h-3v-3ZM9,1.5A7.5,7.5,0,1,0,16.5,9,7.5,7.5,0,0,0,9,1.5ZM9,15a6,6,0,1,1,6-6A6,6,0,0,1,9,15Z"></path></g></svg></span>Add cover letter</button>

How would you get capybara to click on it when it has no name or id. I tried click_link('Add cover letter') but it did not work either.


Solution

  • You should be able to select it by it's class, have you tried that?

    find('button.ia-AddCoverLetter-button').click