While conducting some testing with Selenium, I came across an unusual behavior that appears to be causing the window.onmousemove event to fire repeatedly. This occurs even after the mouse movement has ended, which is not the expected behavior. I am seeking guidance on how to ensure that the onmousemove event only triggers when the mouse is actually being moved. Any assistance would be appreciated.
Below is the code snippet in question:
Public Class Form1
Imports OpenQA.Selenium
Imports OpenQA.Selenium.IE
Imports OpenQA.Selenium.Interactions
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim driver As New InternetExplorerDriver()
driver.Navigate.GoToUrl("http://127.0.0.1:1337/showmouseposition.html")
driver.Keyboard.PressKey(Keys.F12)
Dim builder As New Actions(driver)
Dim ele As IWebElement = driver.FindElement(By.Id("myButton"))
builder.MoveToElement(ele)
builder.Perform()
End Sub
End Class
showmousepositions.html
<html>
<head>
</head>
<body>
<input type="text" id="x">
<input type="text" id="y">
<button type="button" id="myButton" onclick="alert('clicked btn')">Click Me!</button>
<script>
window.doLogging = true;
document.onmousemove = function(e) {
var dot, eventDoc, doc, body, pageX, pageY;
event = event || window.event; // IE-ism
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 );
}
if (doLogging) {
window.x.value = event.pageX;
window.y.value = event.pageY;
console.log(event.pageX + "," + event.pageY);
}
}
</script>
</body>
</html>