Is there a way to programmatically simulate a click event on an HTML DOM element and still retrieve the screenX/screenY and clientX/clientY coordinates successfully? When manually clicking the element, the coordinates are visible in the console, but when triggered programmatically, all coordinates show as 0.
Here are my questions: Q1: Why are the coordinates returning as 0 even though the element is well-positioned? Q2: What adjustments can be made to retrieve the correct coordinates?
Note: The main objective is to create a C# Selenium IJavaScriptExecutor compatible JavaScript code that can capture the current coordinates of an HTML element with a known id attribute. These captured coordinates will then be used as input for creating and simulating a mousewheel event, crucial for zooming functionalities.
<!DOCTYPE html>
<html>
<body>
<h1> Hello </h1>
<h1 id="num1">TEST</h1>
<script>
var myVar = document.getElementById("num1");
myVar.onclick = function(event){ myFunc(event); }; // Manually working fine
myVar.click(); // Not returning Coordinates
function myFunc(e){
console.log(e);
}
</script>
</body>
</html>