Tom
Tom

Reputation: 1227

Chrome Developer Console question

I'm trying to test a feature on my website that produces a random integer. I was wondering if it was possible to use the chrome developer console to trigger a button event with code, without physically pressing the button on the page. Also is it possible to send a different value than what the user put into my textbox. Let's say the user puts his name in "Tom", is there a way to trigger the button event via code in the console as well as change that user input for testing purposes.

Upvotes: 2

Views: 3895

Answers (1)

Eran
Eran

Reputation: 22030

You can run (almost) whatever JavaScript code you want in the console, and it will execute in the context of the page. For instance, to emulate a click on the button, you can type and run:

document.getElementsByTagName("button")[0].click()

which will click the first button found on the page. You can obviously change whatever value in whatever field this way, but I don't fully understand how you expect to do that - you want to bypass the user, but won't the user be sitting in front of Chrome, whose console you'd like to use?

Upvotes: 6

Related Questions