How to navigate a map with Selenium via clicking and dragging

1,384 views
Skip to first unread message

airick

unread,
Mar 3, 2020, 3:36:15 PM3/3/20
to Selenium Users

I am using Selenium and Java to try and automate some google maps navigation. I want to click and hold on the map, then move to a certain direction, then release the cursor. This should move the map across the page.

So far I have

WebElement canvasElement = driver.findElement(map);
Actions builder = new Actions(driver.getWebDriver());
builder
.moveToElement(canvasElement).clickAndHold().moveByOffset(300, 0).release().perform();

However, nothing on the page moves. I know I am selecting the map correctly since if I just do


builder.moveToElement(canvasElement).clickAndHold().moveByOffset(300, 0).perform();

then when I mouse over the map, the map moves without me having to click the left mouse button because it is still in the click and hold state and never released. Not sure why the moveByOffset is not working for this particular case. Any suggestions would be great

Joe Ward

unread,
Mar 3, 2020, 4:07:10 PM3/3/20
to seleniu...@googlegroups.com
May I ask why you are trying to do that? 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/e9db523c-c535-4969-8442-5d32f3e420b5%40googlegroups.com.

airick

unread,
Mar 3, 2020, 4:40:46 PM3/3/20
to Selenium Users
To test a web page with a map


On Tuesday, March 3, 2020 at 1:07:10 PM UTC-8, That Guy wrote:
May I ask why you are trying to do that? 

On Tue, 3 Mar 2020 at 20:36, airick <ericl...@gmail.com> wrote:

I am using Selenium and Java to try and automate some google maps navigation. I want to click and hold on the map, then move to a certain direction, then release the cursor. This should move the map across the page.

So far I have

WebElement canvasElement = driver.findElement(map);
Actions builder = new Actions(driver.getWebDriver());
builder
.moveToElement(canvasElement).clickAndHold().moveByOffset(300, 0).release().perform();

However, nothing on the page moves. I know I am selecting the map correctly since if I just do


builder.moveToElement(canvasElement).clickAndHold().moveByOffset(300, 0).perform();

then when I mouse over the map, the map moves without me having to click the left mouse button because it is still in the click and hold state and never released. Not sure why the moveByOffset is not working for this particular case. Any suggestions would be great

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seleniu...@googlegroups.com.

Joe Ward

unread,
Mar 4, 2020, 1:26:52 AM3/4/20
to seleniu...@googlegroups.com
I think you can be pretty confident Google maps works. I’ve seen people try and fail at this but you may want to consider if it’s even necessary for you to do. 

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/97bf46da-194d-4b5c-ac1b-6f1382e318e5%40googlegroups.com.

airick

unread,
Mar 4, 2020, 12:47:49 PM3/4/20
to Selenium Users
I've been looking around to no avail. Don't know why this simple action is so seemingly complicated but yes it is necessary for this testing effort (not testing google maps functionality but some software functionality laid over it).
Reply all
Reply to author
Forward
0 new messages