开发者

Chrome Developer Console question

I'm trying to test a feature on my website that produces a random integ开发者_Python百科er. 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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜