Is there a way to click on an element with an offset

99 views
Skip to first unread message

Michael Zazzali

unread,
Sep 19, 2013, 7:14:24 AM9/19/13
to clj-we...@googlegroups.com
I want to be able to test some canvas actions and I need to be able to click either at a fixed position or relative to an element(in this case being the canvas element).

I was looking for something along the lines of
 (click "myElement" {:x 50 :y 65})

I looked outside of the clj-webdriver project at the selenium apis and I found 2 more possibilities
Selenium has a mouse interface that you can call mouse up on

And maybe through the Action API

I was unable to get the Action instantiated I tried the below line of code to instantiate a new instance but it doesn't work and I am probably getting ahead of myself with my knowledge of clojure in this case.
 (new org.openqa.selenium.interactions.Actions *driver*)

Does anyone know how I can click at a position or relative to an element?



Michael Zazzali

unread,
Sep 19, 2013, 11:00:57 PM9/19/13
to clj-we...@googlegroups.com
I realized after taking a closer look that the *driver* is just a map, don't know how I missed that so doing (:webdriver *driver*) returns the driver.

Reading the documentation more I also found that the driver contains the actions class already so I was able to put the below statement together but it still won't click relative to the position of my canvas.
(let [act (:actions driver)] (.moveToElement act (:webelement (find-element-by driver {:tag :canvas})) 30 30) (.click act) (.perform act))

I then tried testing a simple div element to see if it was clicking anything at all and just added this to my html

div onclick="alert('test')" test div

And calling this statement
(let [act (:actions driver)] (.moveToElement act (:webelement (find-element-by driver {:tag :div}))) (.click act) (.perform act))

That statement worked so I am getting closer.

I then went ahead and tried the offset again but on the div thinking that this would click outside of the div and not trigger anything
(let [act (:actions driver)] (.moveToElement act (:webelement (find-element-by driver {:tag :div})) 120 120) (.click act) (.perform act))

The bad news is that this also triggered the alert popup, I am not sure why, but it makes me think the offset is not working at all.

Any Ideas?

Michael Zazzali

unread,
Sep 21, 2013, 11:23:45 AM9/21/13
to clj-we...@googlegroups.com
I tried the same code with chrome and it works.  I think this might be a bug with the firefox webdriver or an incompatibility between firefox itself and the version of the webdriver.

Daniel Gregoire

unread,
Sep 21, 2013, 11:27:33 AM9/21/13
to clj-we...@googlegroups.com

Sorry to reply late in the game. Element locations are calculated differently for Selenium in Chrome and Firefox, so hardcoded location/offset tests are less reliable. IIRC, Chrome uses the center of the element while Firefox uses the top-left corner.

On Sep 21, 2013 11:23 AM, "Michael Zazzali" <michael...@gmail.com> wrote:
I tried the same code with chrome and it works.  I think this might be a bug with the firefox webdriver or an incompatibility between firefox itself and the version of the webdriver.

--
You received this message because you are subscribed to the Google Groups "clj-webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clj-webdrive...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages