1

Using JavaScript I am atempting to simulate a click. This will be performed on a flash clip swf file. Using the following code. Here is what I have come up with.

countDown = 10;
var rollDice = setInterval(function() {
    console.log(countDown);

    if (countDown == 0) {
        clearInterval(rollDice);
        document.elementFromPoint(416, 825).click();
    }
    countDown--;
}, 1000);

With this code I get the following error: Uncaught TypeError: Cannot call method 'click' of null.

Daniel
  • 4,202
  • 11
  • 50
  • 68
  • Duplicate http://stackoverflow.com/questions/3277369/simulate-a-click-by-using-x-y-coordinates-javascript http://stackoverflow.com/questions/2890921/simulating-click-with-javascript-on-document – zessx Jun 02 '12 at 01:01
  • right, it's a dupe - but also the flash object wouldn't receive click events emitted by the DOM, as browser plugins handle mouse events by themselves. – Leonhardt Wille Jun 02 '12 at 01:08

1 Answers1

1

I'm not sure if clicking on an item by coordinates rather than a jQuery selector is a good idea. Why do you have to do the click event via coordiates rather than select the button that is being pressed?

You issue seems to be due to the fact that elementFromPoint doesn't return a jQuery Object, try this instead:

$(document.elementFromPoint(416, 825)).click();
Jason Kulatunga
  • 5,814
  • 1
  • 26
  • 50