I am trying to implement an \"object picker\" to my Selenium based framework as is common on most commercial automation tools. To do this I am using a Javascript command to
It's actually about how you are passing the coordinates into the script. Script arguments has to be specified separately as separate ExecuteScript() arguments. What was happening in your case is that you have basically specified one x argument which made it think that y should be considered a default 0 value. And at y=0 there is usually a header.
Instead of:
ele = (IWebElement)((IJavaScriptExecutor)driver).ExecuteScript(
"return document.elementFromPoint(arguments[0], arguments[1])",
new int[] { Cursor.Position.X, Cursor.Position.Y });
You should do:
ele = (IWebElement)((IJavaScriptExecutor)driver).ExecuteScript(
"return document.elementFromPoint(arguments[0], arguments[1])",
Cursor.Position.X, Cursor.Position.Y);