Chrome Developer Console question

北城余情 提交于 2020-02-02 12:11:27

问题


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.


回答1:


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?



来源:https://stackoverflow.com/questions/6725992/chrome-developer-console-question

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!