0

I am trying to automate a website test using JavaScript. Part of my tests include clicking a button that has a type, but no id.

I've tried to do this using a jQuery code that I found online but it didn't work. Is there any way to simulate the click using the type of the button?

This is the HTML of the button I am trying to target:

<button type="submit">Go</button>
6
  • People can't hep you very well if you don't show us the code you're working with Commented Nov 19, 2019 at 13:15
  • Please do not repeat text, there is no valid reason for it. Commented Nov 19, 2019 at 13:17
  • "<button type="submit">Go</button>" am trying to stimulate the click on that button Commented Nov 19, 2019 at 13:19
  • $('button[type="submit"]') should select that Commented Nov 19, 2019 at 13:21
  • You can use a type attribute as a selector in finding the button ie jQuery('[type="button"]') as for simulating the click and triggering an event listener you would use jQuery's trigger() method. But if that didn't work you need to explain exactly you want to happen when that button is clicked, eg event handler trigger vs something like default form submission from button click Commented Nov 19, 2019 at 13:23

1 Answer 1

1

You can use the jQuery attribute selector, $(element[attribute='value'])

$('button[type="submit"]')

You can have a look at the documentation here if you want to understand more of the selector - you can do things such as select based on the start / end of an attribute, or if it is not the value you give

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.