Chrome开发人员控制台问题 [英] Chrome Developer Console question

查看:156
本文介绍了Chrome开发人员控制台问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要测试我网站上产生随机整数的功能。我想知道是否可以使用chrome开发人员控制台触发一个按钮事件的代码,没有物理按下页面上的按钮。也可以发送不同于用户放入我的文本框中的值。让我们假设用户将他的名字放在Tom中,是否有一种方法可以通过控制台中的代码触发按钮事件,并更改用户输入以进行测试。

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.

推荐答案

你可以运行(几乎)任何你想在控制台中的JavaScript代码,它将在页面的上下文中执行。例如,要模拟对按钮的点击,可以键入并运行:

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()

这将点击页面上的第一个按钮。你可以明显改变任何字段中的值,这种方式,但我不完全明白你希望如何 - - 你想绕过用户,但不会让用户坐在Chrome的前面,其控制台, d喜欢使用?

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?

这篇关于Chrome开发人员控制台问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆