C# – Selenium click on coordinates not clicking where expected

c++screen-scrapingselenium

I need to screen scrape a webpage that is using ActiveX controls for the navigation. This is not for ui testing purposes, its for data downloads from a legacy application.

The issue I have is the top navigation is complete ActiveX with javascript and is impossible to get the elements by anything. So I am trying to do mouse clicks at the coordinates.

I am using the following method answer by Bergstrom

Basically I am doing

var action = new Actions(ieDriver).MoveToElement(ieDriver.FindElement(By.Tag("HTML"))).MoveByOffset(200,100).Click().Perform();

I confirmed while debugging that ieDriver.FindElement returns -1,-1 for the location of the HTML tag, so the offset coordinates should be correct.

I measured the coordinates using IE Toolbar. When I run the code nothing happens, so I assume its click in blank space.

Is there a way to ping the browser so I know where the coordinates are or is there a better way of achieving this?

I was able to successfully do this using VS Coded Unit Test since it actually moves the cursor, but I don't think the licensing will allow me to use that option as well as the annoyance of getting it to run outside of visual studio.

Best Solution

I spent like 2 hours trying to get it to work, I had an element inside iframe,

keep in mind there's a lot of code examples in internet that don't work, I eventually settled to this one which actually works exactly as it has to:

_driver.SwitchTo().Frame(recaptchaChallengeFrame);

var body = _driver.FindElement(By.XPath(".//body"));

Actions builder = new Actions(_driver);

builder
    .MoveToElement(body, absClickX, absClickY)
    .Click()
    .Build()
    .Perform();
Related Question