Selenium click on coordinates without clicking where expected

I need to screen a webpage using ActiveX controls for navigation. This is not for ui testing purposes, it is for loading data from an outdated application.

The problem I ran into is top navigation full of ActiveX with javascript and it is impossible to get elements with anything. Therefore, I am trying to make mouse clicks in the coordinates.

I use the following Bergstrom answer method

Mostly i do

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

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

I measured the coordinates using the IE toolbar. When I run the code, nothing happens, so I assume it clicks into empty space.

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

I was able to successfully accomplish this with the VS Coded Unit Test, since it really moves the cursor, but I don’t think that licensing will allow me to use this option, as well as the annoyance of making it work outside of visual studio.

+6
source share
2 answers

Instead of trying to force an element to simply move at an offset. Make sure you know what your priority is ... If not, then this should be the top left corner of the page. Then put your dream in the middle and you can see the movement of the mouse, wait, and then click.

 Actions action = new Actions(driver); action.MoveByOffset(200,100).Perform(); Thread.Sleep(10000); action.Click(); 
+4
source

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

Remember that there are many code examples on the Internet that don’t work. In the end, I decided that it works exactly as it should:

 _driver.SwitchTo().Frame(recaptchaChallengeFrame); var body = _driver.FindElement(By.XPath(".//body")); Actions builder = new Actions(_driver); builder .MoveToElement(body, absClickX, absClickY) .Click() .Build() .Perform(); 
+2
source

Source: https://habr.com/ru/post/974008/


All Articles