2

I need to click at an x,y offset of an image. How do I do it using Javascript?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
C R Lakshmi
  • 77
  • 1
  • 10
  • The title of your post says `mouse over` (hover) but your question asks about `click`. Tha's a litle bit confusing. Here is a good source for information about simulating hover: http://stackoverflow.com/questions/11728406/simulate-hover-using-javascript-events – David Tansey Apr 15 '13 at 05:57
  • There is a example in this link https://developer.mozilla.org/en-US/docs/DOM/document.createEvent – karthick Apr 15 '13 at 05:57
  • @karthick: I tried this $(document.elementFromPoint(315, 270)).click(); – C R Lakshmi Apr 15 '13 at 06:01
  • @DavidTansey: I need to click at x/y offset. – C R Lakshmi Apr 15 '13 at 06:02

3 Answers3

0

To be clear, you will not be able to move to some x,y and click. You can only simulate event using createEvent. You can find the documentation here. https://developer.mozilla.org/en-US/docs/DOM/document.createEvent

0

There are always so many methods to fulfill 1's requirement. But its always important to pick the best one.

In your case what I interpret is, you want to call a JS function with params as X & Y coordinates. And if you want some specific X, Y values then why you want to simulate click / hover event when you can directly call the JS with static coordinates values.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Amit Sharma
  • 1,202
  • 11
  • 26
  • You are right Amit but, I am using it for an automated testing tool where providing the function wouldn't be an appropriate options for the testers who will not know about whats in the code. – C R Lakshmi Apr 15 '13 at 09:18
  • so you want to trigger click event from automated testing tool like selenium. Event than you have to specifically write the code to click on the HTML element. – Amit Sharma Apr 15 '13 at 11:07
-2

You can refer this too. jquery trigger

Aaron
  • 77
  • 2