jeudi 21 juin 2018

TamperMonkey can't click button

This is the website I want to use TamperMonkey to click button. This is my script code:

// ==UserScript==
// @name         click
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://secure.timesheets.com/
// @include      https://secure.timesheets.com/default.cfm?page=Login&CFID=*
// @grant        none
// ==/UserScript==
start();
function start() {
    'use strict';
    var domd = document.getElementById('large-button-clockin');
    console.log(domd);
    function sleep(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
    }

    async function demo() {
        console.log('Taking a break...');
        await sleep(10000);
        console.log('Ten second later');
        document.getElementById('large-button-clockin').click();
    }
    demo();
};

It shows:

<button class="largeButton loginButton" name="HourlyClockInButton" id="large-button-clockin" data-login-value="IN" type="button">HOURLY<div>CLOCK IN</div>CLICK HERE</button>
Taking a break...

And when the time arrives, it looks just like it refresh the page not click the button, and the CFID code change to another one. BTW, the browser would fill my form automatically.

But if I just put the code document.getElementById('large-button-clockin').click(); in the console of browser. It would click the code. But I can't do this in the TamperMonkey.

Do you know why?




Aucun commentaire:

Enregistrer un commentaire