Accepted answer

If it's the only button with tabindex="0" you can just do


If you can come up with a css or xpath expression to select the button (and it's visible on the page) you can click it without using execute_script (you're better off not using execute_script because the events are closer to what a user would generate). Another option is if the button is the only button contained inside an identifiable element you can scope your find to the identifiable element.


or if it's the first button in a section


or if it's just the first button on the page and you're coming from a page with no buttons

all('button', minimum: 1)[0].click()

Your execute_script didn't work because you're searching by class name but according to your html the button doesn't have any class attribute set. Anyway you're always better off with Capybara not using execute_script if possible, since execute_script has no waiting or retrying behavior associated with it and shortcuts a number of checks which confirm could actually do the action you want tested.

Related Query

More Query from same tag