0

I am trying to write a script to use a script to open a website and click a button.

I can actually use window.location.href = '...'; or $("#id").click() to do that separately. But if I run the first one, the second one wouldn't run because we would lose it.

I just want to know is there any way to run the code one by one?

update: No I can't control it. It is a public website.

Weiheng Li
  • 39
  • 1
  • 1
  • 8

1 Answers1

1

It's pretty simple, but you can only use it in your own browser (or in anyones browser who has this userscript installed). For example, for tampermonkey in chrome you could use

// ==UserScript==
// @name         Button clicker
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Click a button
// @author       You
// @match        <replace with website you want the button to be clicked>
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    document.getElementById('id').click();
})();
baao
  • 71,625
  • 17
  • 143
  • 203
  • It is a good idea. But actually it doesn't work in my website i don't know why. This website https://secure.timesheets.com/?CFID=239387727&CFTOKEN=a1d7cde00b4d84f8-554A5D51-5056-850F-66D6C0144776E3ED It works if I just put the click js code in console, it can click the button but doesn't if I put it in the script. It would just looks like refresh the page and the following CFID code in the url change to another one. – Weiheng Li Jun 21 '18 at 14:55
  • Which button do you want to click there @WeihengLi – baao Jun 21 '18 at 15:20
  • https://stackoverflow.com/questions/50971986/tampermonkey-cant-click-button You can find more info here. – Weiheng Li Jun 21 '18 at 15:33