RE: [webdriver] How to click on a specific coordinates of a webelement

7,457 views
Skip to first unread message

Mark Collin

unread,
Jul 24, 2012, 9:31:06 AM7/24/12
to webd...@googlegroups.com

Try the following:

 

WebElement baseElement = driver.findElement(By.id("foo"));

Actions clicker = new Actions(driver);

clicker.moveToElement(baseElement).moveByOffset(X, Y).click().perform();

 

Where X and Y are pixels along the horizontal and vertical plane

 

From: webd...@googlegroups.com [mailto:webd...@googlegroups.com] On Behalf Of brajasundar dash
Sent: 24 July 2012 14:16
To: webd...@googlegroups.com
Subject: [webdriver] How to click on a specific coordinates of a webelement

 


Hi,

Could any one let me know, how to click on particular coordinate of a web-element using selenium webdriver, if the web-element is a vertical separation line having more than one coordinates.

Thanks,
Brajasundar

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/IhniwTRTfn0J.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.

vamsi krishna

unread,
Dec 28, 2015, 9:55:13 AM12/28/15
to webdriver
Try this

WebElement e = driver.findElement(By.xpath("html/body/form/div[4]/div[2]/div/div[6]/div[2]/div/table/tbody"));
        Coordinates co = ((Locatable)e).getCoordinates();
        co.inViewPort(); 

darrell

unread,
Dec 29, 2015, 7:49:04 AM12/29/15
to webdriver
Three things. First, I have always did a build() before I did a perform(). Now sure if this will make a difference but I'd always use:

clicker.moveToElement(baseElement).moveByOffset(X, Y).click().build().perform();

Second, I vaguely remember that the X,Y coordinates didn't work the way I expected. I think I was assuming it was from the upper left corner of the screen then to the right X pixel and down Y pixels. Plus I wasn't sure if it was from the edge of the element or if it included the padding and border for the element.

Third, there is a moveToElement() which takes (baseElement, x, y). So you can shorten it to:

clicker.moveToElement(baseElement, X, Y).click().build().perform();

As I was learning this stuff I would not chain the method calls. When I ran it, I could actually watch it (it was fast but not as fast) moving. Or I could do things like:

clicker.moveToElement(baseElement, X, Y).moveByOffset(X, Y).moveByOffset(X, Y).moveByOffset(X, Y).moveByOffset(X, Y).moveByOffset(X, Y).moveByOffset(X, Y).moveByOffset(X, Y).moveByOffset(X, Y).click().build().perform();

The multiple .moveByOffset(X, Y) didn't really do anything from the test point of view but it slowed things down a lot in order to see where it was clicking things.

PeterJeffreyGale

unread,
Dec 29, 2015, 1:17:12 PM12/29/15
to webdriver
It's a shame that google groups doesn't prevent someone from re-opening a thread that's so old. I do hope the OP wasn't sat waiting for further help.

darrell

unread,
Dec 30, 2015, 7:23:40 PM12/30/15
to webdriver
I get a daily digest. Normally I notice if someone has replied to a really old thread but I guess I missed this time. lol. I'll look into whether threads can be automatically archived/closed after a specific period of inactivity. Even if Mark isn't waiting for an answer it might benefit someone else who is searching for the answer. You are right though that we should have some way to archive/close this message if they are say over 1 year old.
Reply all
Reply to author
Forward
0 new messages