How can I click on a pin in a Google map embedded from JavaScript?

RobotHumans

There is a map embedded in a webpage. I want to click on a pin in the map. I can inject JS onto a page, or use any API that is available to Selenium.

The problem is that I can't find the pin in the embedded map on the page.

Possible solutions:
I've thought about getting ahead of it and diverting registration for the click listener, but I would appreciate it if someone has done this before and can offer me a tip.

RobotHumans

It was for a test case with Nightwatch.js where I needed to click on a pin in the map(location). Since I can control test cases and only have one location, I could just assume the view was centered on the pin. So:

browser.execute(function() {
function clickPin(){
 var elem = document.getElementsByClassName('map-canvas')[0];
 var rect = elem.getBoundingClientRect();
 var centerY = (rect.bottom - rect.top);
 var centerX = (rect.right - rect.left);
 var divX = document.createElement("div");
 divX.style.visibility = 'hidden';
 divX.id = 'offsetX';
 divX.innerHTML = centerX.toString();
 var divY = document.createElement("div");
 divY.style.visibility = 'hidden';
 divY.innerHTML = centerY.toString();
 divY.id = 'offsetY';
 document.head.appendChild(divX);
 document.head.appendChild(divY);
}
clickPin();
}, [], function(result){});
browser.pause(3000);
browser.waitForElementPresent(`//*[@id="offsetX"]`, 3000);
var relX = browser.getValue(`//*[@id="offsetX"]`);
var relY = browser.getValue(`//*[@id="offsetY"]`);
//set cursor position to center and click (fragile)
browser.moveToElement(`//*[@class="map-canvas"]`, relX, relY).mouseButtonClick();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I add a pin to my Google Map from Google Developers Tutorial

From Dev

how can i disable right click on Google map infowindow

From Dev

How can I create a click event on a google map marker in a cluster?

From Dev

How to pin on a google map for iOS?

From Dev

How to get location from Google Map after dropping Pin over it

From Dev

How do hide latitude and longitude from pin on google map

From Dev

How can I extract pin property from an object and make an array of pins in JavaScript?

From Dev

Google map pin title from json array

From Dev

How to add pin point on Google Map using package (when you click on a button, it open directly to Google Map App) on android studio

From Dev

Google map drag pin from inside a div on google map

From Dev

How to add drop pin in Google Map iOS

From Dev

How to get google maps style from a embedded map

From Dev

Javascript - Returning a value from google map click listener event

From Dev

How can I: Select a paragraph with JavaScript (on click)?

From Dev

How can I use javascript to click these elements?

From Dev

How can I correct the marker on google map

From Dev

How can I use onkeypress without javascript embedded into the html?

From Dev

How can I use onkeypress without javascript embedded into the html?

From Dev

Google Map get current location that can be changed by dragging the pin

From Dev

Google Map get current location that can be changed by dragging the pin

From Dev

How can i prevent onclick button from multiple click until it's confirmation from javascript if(confirm ) condition

From Dev

How can I pin a certificate with Square OKHTTP?

From Dev

How can I pin a CHM file to the taskbar?

From Dev

How can I pin a file to the bookmarks?

From Dev

How to open Google Map when I click on a button in android app

From Dev

How can I remove the youtube branding completely from embedded video?

From Dev

how can I read embedded controller version from Windows 8.1?

From Dev

How can I remove the youtube branding completely from embedded video?

From Dev

how can I read embedded controller version from Windows 8.1?

Related Related

  1. 1

    How do I add a pin to my Google Map from Google Developers Tutorial

  2. 2

    how can i disable right click on Google map infowindow

  3. 3

    How can I create a click event on a google map marker in a cluster?

  4. 4

    How to pin on a google map for iOS?

  5. 5

    How to get location from Google Map after dropping Pin over it

  6. 6

    How do hide latitude and longitude from pin on google map

  7. 7

    How can I extract pin property from an object and make an array of pins in JavaScript?

  8. 8

    Google map pin title from json array

  9. 9

    How to add pin point on Google Map using package (when you click on a button, it open directly to Google Map App) on android studio

  10. 10

    Google map drag pin from inside a div on google map

  11. 11

    How to add drop pin in Google Map iOS

  12. 12

    How to get google maps style from a embedded map

  13. 13

    Javascript - Returning a value from google map click listener event

  14. 14

    How can I: Select a paragraph with JavaScript (on click)?

  15. 15

    How can I use javascript to click these elements?

  16. 16

    How can I correct the marker on google map

  17. 17

    How can I use onkeypress without javascript embedded into the html?

  18. 18

    How can I use onkeypress without javascript embedded into the html?

  19. 19

    Google Map get current location that can be changed by dragging the pin

  20. 20

    Google Map get current location that can be changed by dragging the pin

  21. 21

    How can i prevent onclick button from multiple click until it's confirmation from javascript if(confirm ) condition

  22. 22

    How can I pin a certificate with Square OKHTTP?

  23. 23

    How can I pin a CHM file to the taskbar?

  24. 24

    How can I pin a file to the bookmarks?

  25. 25

    How to open Google Map when I click on a button in android app

  26. 26

    How can I remove the youtube branding completely from embedded video?

  27. 27

    how can I read embedded controller version from Windows 8.1?

  28. 28

    How can I remove the youtube branding completely from embedded video?

  29. 29

    how can I read embedded controller version from Windows 8.1?

HotTag

Archive