[英]What should I do if I want to click button on the new page while running snippet on chrome dev tools
I try to run some JS snippet in chrome dev tools , but not sure what I should do here. 我尝试在chrome开发工具中运行一些JS代码段 ,但不确定在这里应该做什么。 Can anyone help here?
有人可以帮忙吗? Thanks.
谢谢。
Take StackOverflow site for example. 以StackOverflow网站为例。 The script clicks the navigator tab "Jobs" to a new page then clicks the button "Create alert" on it.
该脚本单击导航器选项卡“作业”到新页面,然后单击其上的“创建警报”按钮。
see image for more information.
请参阅图像以获取更多信息。
f1 works separately and also f2, but they do not work if I put them together. f1和f2分别工作,但是如果我将它们放在一起,它们将无法工作。 what should I do if I hope them work together?
如果希望他们能一起工作该怎么办?
function f1(){ //click the nav-jobs document.getElementById("nav-jobs").click(); } function f2(){ // create the button "Create alert" on the job page document.getElementById("reg-alert-model").click(); } f1(); setTimeout(f2, 5000);
Function call f2()
will not occur because a page transition has already occurred after executing f1()
. 执行
f1()
之后已经发生页面转换,因此不会发生函数调用f2()
f1()
。
JavaScript function calls do not persist in the call stack between page transitions. 在页面转换之间,JavaScript函数调用不会保留在调用堆栈中。
When a page is reloaded or a new page is loaded, the entire context of the previous page is cleared/reset. 重新加载页面或加载新页面时,将清除/重置上一页的整个上下文。 So you can't keep a timer running over a document change.
因此,您不能让计时器在文档更改上运行。 Naturally, when running them separately (no, not seperately ), there are no context changes, so it works as you expect.
自然地,当分别运行它们(不,不是单独运行 )时,没有上下文更改,因此可以按预期工作。 But if you change the context in between, everything is lost, including the timer.
但是,如果您在两者之间更改上下文,则所有内容都将丢失,包括计时器在内。 Using the developer tools does not do any magic in keeping the context, it does not really matter whether you run it in the console or in the "page code".
使用开发人员工具对保持上下文没有任何魔力,无论是在控制台中还是在“页面代码”中运行它都没有关系。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.