1

I'm making some automation script. I could imitate the mouse-click using that automation tools but the coordinates changes over device so I rather make it through browser console.

I could do it with normal <button> by using element.click() but I couldn't do it with <div>

What I want to do is click the start button (はじめから) using console like element.click() ss

you could try it here

So far, I have tried:

document.getElementById('start').click();

and

a = document.getElementById('start').getBoundingClientRect();
document.elementFromPoint(((a.width / 2) + a.left), ((a.height / 2) + a.top)).click();

but nothing happens

Is it possible to do this with browser console?

Thanks in advance

Eternity Neet
  • 179
  • 4
  • 17
  • the `.click()` function is from jQuery. Thus, you would need to get the jQuery element, like this : `$('#start').click()` – Seblor Jun 29 '17 at 14:49
  • Why don't you trigger the same function that the click triggers instead of clicking on the page from console? – JustARandomProgrammer Jun 29 '17 at 14:50
  • @JustARandomProgrammer I guess OP wants to click on a button where the inner code of the event in unknown. – Seblor Jun 29 '17 at 14:51
  • Possible duplicate of [How to simulate a mouse click using JavaScript?](https://stackoverflow.com/questions/6157929/how-to-simulate-a-mouse-click-using-javascript) – Seblor Jun 29 '17 at 14:52
  • @Seblor I could use `.click()` just fine on ` – Eternity Neet Jun 29 '17 at 15:29

1 Answers1

1

The page has somehow, in some way, disabled event bubbling and propagation, I suppose.

I tried the below code in stackoverflow console and the page's console, but only stackoverflow's console is having respond.

document.body.addEventListener('click', function(e){
    console.log('clicked' + e.target);
});

document.body.dispatchEvent(new Event('click'));
yqlim
  • 6,898
  • 3
  • 19
  • 43
  • interesting click finder, but still doesn't help in my case :( – Eternity Neet Jun 29 '17 at 15:33
  • Even after implementing the code from console, you can't log anything into console even after manually clicking (it should log something). So I guess you just can't do automation there (maybe you can, but I don't know how). – yqlim Jun 29 '17 at 15:36