greenwaterboy greenwaterboy - 10 months ago 64
C# Question

Selenium click on coordinates not clicking where expected

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.

Answer Source

Rather than trying to get an element just move by offset. Make sure you know what your prior focus is... If none then it should be the top left corner of the page. Then put your sleep in the middle and you should be able to see the mouse move, wait, and then click.

Actions action = new Actions(driver);