Selenium Webdriver. Inaccurate mouse actions in Internet Explorer 9

Greetings to all!

I am not a native speaker of English, so sorry for my fair grammar.

Selenium is the basis for testing web applications in different browsers. I want to ask people who use Selenium for any help. I asked people at the Selenium Google Group, but no one helped me.

I am working on a project with a lot of mouse interaction using Selenium Webdriver. I am writing tests in C #. When my team started using Selenium Webdriver, we noticed that mouse actions (OpenQA.Selenium.Interactions.Actions) have slightly unexpected behavior in IE and work differently in different browsers (and even on different machines). For the first time, I was the only tester to work with mouse actions. I blamed Selenium Webdriver and I tried to find a way to avoid this inaccuracy. I studied this problem for a long time, but without any results. But I do not want to waste your time on the background.

Ok, let me describe the situation. We have created a demo project: a simple page with. And we realized the ability to draw on this canvas by holding the left mouse button. Therefore, I hope this is pretty clear to you.

The next important point is that we turned on logging for the console. That is, we can see the coordinates of the mouse arrow inside the canvas, opening the console.

Then we wrote a test:

Actions a = new Actions(driver); a.Build(); a.MoveToElement(canvas, 100, 100) .ClickAndHold() .MoveByOffset(100, 0) .Release(); a.Perform(); 

The code is pretty simple. Just moving the mouse arrow to the canvas, then move the mouse arrow to (100, 100), and then move vertically to 100 (with the left left mouse button). As you can understand, the result in the logs should be (200, 100).

But here is the most interesting: my colleagues have the same result (200, 100)! But they had an inaccuracy 1 month ago (why did we think that the mouse actions were not accurate). And I still have an inaccurate result: (192, 96). Thus, there is a 4px error at 100px offset. My colleagues do not understand what they have changed and why the mouse actions are working correctly or now.

Another interesting thing is that visually (I remind you that we can draw on the canvas) it is absolutely 100px (we hold the mouse button while moving the mouse arrow vertically)! Amazing

So this experiment.

I ask all suitable people to help me solve this problem. It appears only in IE9. And I want to understand the reason for this behavior. How is an action class performed? Does it depend on the mouse driver or something similar? In this case, if that matters, I use a wireless mouse and it has a special driver. Please help me!

PS I tried to change my mouse settings, my screen settings, but no results.

Thanks!

Sincerely, Mikhail Kalygin.

+4
source share
2 answers

Make sure that the zoom level in IE9 is set to 100% - that the only thing I can think about is to compensate your coordinates by 4%.

+4
source

I slightly changed the sequence of actions to suit my needs. It works fine for IE8, but Firefox and Chrome don't like this. I am trying to drag an element with some offset (100 100), but FireFox throws an exception saying that the target is out of bounds and gives some crazy coordinate numbers that don't match what I'm doing. Chrome just doesn't move the item.

My problem is that the graph is a third-party widget that uses svg for chrome and Firefox. In IE, I could use the general β€œcell” search methods on the graph, but Firefox and Chrome do not allow me to find the element (s) by identifier, class, or anything else. Therefore, I have a javascriptExecutor that I can use to get all the data in the cells of the graph, including the x, y position of the cell in the graphical widgets. I can get the location of the graph widget since there is a "div wrapper" for the graph. using the location of the graph, I do the following:

 Point mxPoint = driver.GetElementPosition(GraphicalDisplayPage.GraphDisplayPaneById); Actions moveCell = new Actions(driver); moveCell.Build(); moveCell.MoveByOffset(mxPoint.X, mxPoint.Y);//move mouse to upper left corner of graph moveCell.MoveByOffset(xOfCelltoMove, yOfCellToMove);//move mouse to cell we want to move moveCell.ClickAndHold();//select cell and hold it moveCell.MoveByOffset(100, 100);//drag cell moveCell.Release();//drop it moveCell.Perform();//run this set of actions 

Ok, I understood my problem. I need to get the size of a graph element and divide the height and width by 2 and negate these values ​​for negative offsets. Then my first move relates to the location of the graph element (center of the element), then moves to negative offsets to get the top left corner, and then shift the offset by xOfCelltomove and yOfcelltomove. and I'm good to go. I also added 10 to xOfCellToMove and yOfCellToMove to move the mouse cursor over the vs element over the left corner of the element, making it more consistent so that the actions look like this:

 Size mxSize = driver.GetElementSize(GraphicalDisplayPage.JGraphDisplayPaneById); mxSize.Height = -(mxSize.Height/2); mxSize.Width = -(mxSize.Width/2); //create the action and do it Actions moveCell = new Actions(driver); moveCell.Build(); moveCell.MoveToElement(driver.FindElement(GraphicalDisplayPage.JGraphDisplayPaneById)) //mxPoint.X, mxPoint.Y) //move mouse to center of graph .MoveByOffset(mxSize.Width, mxSize.Height)//move mouse to top left corner of graph .MoveByOffset(xOfCelltoMove , yOfCellToMove) //move mouse to cell we want .ClickAndHold() //select cell and hold it .MoveByOffset(100, 100) //drag cell .Release();//drop it moveCell.Perform();//run this set of actions 
0
source

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


All Articles