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.
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.
Comments