Yeah, this problem is frustrating.
This method will allow you to see where the mouse is by painting a red dot on it:
Start by adding the following CSS to your webpage, temporarily:
// TODO: Remove me after you've figured out where the mouse is moving to.
.dot {
background: red;
position: absolute;
width: 2px;
height: 2px;
z-index: 10000;
}
Then, in your code, just before you're calling the *.moveTo()
method, add a pause to allow you to inject code into the browser's console. This code is in JavaScript (JS / webdriver.io) but it's easy to add in any language:
// Other test stuff...
console.log("This gives you 10 seconds to inject the code..."); // <-- Add this and the next line
browser.pause(10000);
browser.moveTo(...gawdKnowsWhere);
Now, when you see the test command line console is waiting 10 seconds, open up Chrome/Firefox's developer tools (F12) and paste this snippet into the browser's "Console" tab:
(function() {
"use strict";
document.onmousemove = handleMouseMove;
function handleMouseMove(event) {
var dot, eventDoc, doc, body, pageX, pageY;
event = event || window.event; // IE-ism
// If pageX/Y aren't available and clientX/Y
// are, calculate pageX/Y - logic taken from jQuery
// Calculate pageX/Y if missing and clientX/Y available
if (event.pageX == null && event.clientX != null) {
eventDoc = (event.target && event.target.ownerDocument) || document;
doc = eventDoc.documentElement;
body = eventDoc.body;
event.pageX = event.clientX +
(doc && doc.scrollLeft || body && body.scrollLeft || 0) -
(doc && doc.clientLeft || body && body.clientLeft || 0);
event.pageY = event.clientY +
(doc && doc.scrollTop || body && body.scrollTop || 0) -
(doc && doc.clientTop || body && body.clientTop || 0 );
}
// Add a dot to follow the cursor
dot = document.createElement('div');
dot.className = "dot";
dot.style.left = event.pageX + "px";
dot.style.top = event.pageY + "px";
document.body.appendChild(dot);
}
})();
Now, go hunting for a red dot. Wherever the mouse is moved to, it will not be able to click there because there's a red square in the way now. But at least you can see where it's trying to go.
Can't see the dot?
Some tips:
- Make the dots bigger in the CSS by modifying the width & height.
- Move your mouse across the screen and watch all the red dots. Are they showing up when you move your mouse?
- Make sure you can paint a red dot where you expect it to be. The z-order might not be high enough, etc.