score:1
If it's the only button with tabindex="0" you can just do
find('button[tabindex="0"]').click()
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.
find('form#my_form').find('button').click()
or if it's the first button in a section
find('form#my_form').all('button')[0].click()
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.
Source: stackoverflow.com
Related Query
- UI react capybara button click test
- React Jest Enzyme - Can not get simple Button Click test to pass
- How to test the child component render text after the button on the parent component click with react testing library?
- How to test button that on click renders html element within the same component in React testing library, Jest?
- How to navigate on path by button click in react router v4?
- Deactivate input in react with a button click
- How can I get an input's value on a button click in a Stateless React Component?
- Test that a click event in React updates the HTML
- How can I find and click a button that has no text using React Testing Library?
- React Formik bind the external button click with onSubmit function in <Formik>
- Scroll page to the nested React component on a button click
- React scroll component horizontally on button click
- How I can disable a button in React js for 5 seconds after click event
- React Bootstrap + Formik - show errors after I click submit button
- Append a React component in another on button click
- React - Fetch from external API function on button click
- Detect button click from WebView in React Native
- How to change Cursor Icon upon button click on React
- React native button click move to another screen
- How to test a click event with enzyme in a React component's dangerouslySetInnerHTML content
- Add and Remove HTML Elements on Button Click in React
- Foundation, React throw "el.data(...).split is not a function" when click on toggle button
- react native Horizontal Scroll on Button click
- React Jest test button onClick
- React update input value on button click
- React Formik onSubmit RestAPI called twice, once click a submit button
- Passing button click from child to parent in React
- Test that another component is rendered on button click ReactJS
- React Routers not working on button click
- React Component Doesn't Update After First Button Click
More Query from same tag
- Add object key to end of a href url link?
- code splitting with dynamic imports with typescript
- How to make sidenav mobile link in react js about this situation?
- React - enable/disable component when we click on one img
- How to pass JSON with @ symbol to props in React
- Should a React component use (fixed) values not on state or props?
- How to get variable colors from database with Axios and then apply them in Scss - ReactJs
- Passing Function Down [React]
- create array of object from array of strings
- How to properly use Router inside Router in React
- react app browser proxy with http-proxy-middleware
- How to target a specific element in react map loop
- How to use foundation css with webpack and react?
- The search icon won't appear when using MDBIcon
- How to store unique item in react redux?
- Expanded View using Html Css For Given Design
- How can I remove event Listener so it would not try to update state when component is unmounted?
- How to fill 100% of height and width of Ant Card?
- Adding onclick to dynamically created span tag
- Mongoose findOneAndUpdate don´t update and don´t throw an error
- How to add scroll bar to a react component?
- Receiving 404s in my React app despite setting historyApiFallback to true for webpack-dev-server
- How to prevent default handling of touch events?
- How to get the last part of the current URL with react router v6?
- Cloud function for express firebase pagination
- How to check object in React for null or empty or undefined?
- Multiple calls to state updater from useState in component causes multiple re-renders
- How to prevent component from being re-rendered unnecessarily
- Material-UI: Too many re-renders. The layout is unstable. TextareaAutosize limits the number of renders to prevent an infinite loop
- Implementing Lodash's debounce in a ReactJS functional component