简体   繁体   中英

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. Can anyone help here? Thanks.

Take StackOverflow site for example. 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. 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() .

JavaScript function calls do not persist in the call stack between page transitions.

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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM