Selenium Webdriver. Mouse actions inaccuracy in Internet Explorer 9 Selenium Webdriver. Mouse actions inaccuracy in Internet Explorer 9 selenium selenium

Selenium Webdriver. Mouse actions inaccuracy in Internet Explorer 9


Make sure the zoom level in IE9 is set to 100% - that's the only thing I can think of that would offset your coordinates by 4%.


I slightly modified the sequence of actions to fit my needs. It works great for IE8 but Firefox and Chrome do not like it. I am trying to drag and drop an element by some offset (100,100) but FireFox throws an exception saying the target is out of bounds and gives some crazy coordinate numbers that do not match what I am doing. Chrome just doesn't move the element.

My problem is that the graph is a third party widget that uses svg for chrome and Firefox. In IE I could use common techniques for finding "cells" on the graph, but Firefox and Chrome do not allow me to find an element(cells) by Id, Class or anything. So I have a javascriptExecutor that I can use to get all graph cells data including x,y position of cell on the graph widget. I can get the graph widget location as there is a "wrapper div" for the graph. using the graph location 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 graphmoveCell.MoveByOffset(xOfCelltoMove, yOfCellToMove);//move mouse to cell we want to movemoveCell.ClickAndHold();//select cell and hold itmoveCell.MoveByOffset(100, 100);//drag cellmoveCell.Release();//drop itmoveCell.Perform();//run this set of actions

Ok I figured out my problem. I need to get the size of the graph element and divde Height and Width by 2 and negate those values for negative offsets. Then my first Move is to the graph element's location (center of element) then move to the negated offsets to get upper left corner, then move by offset to xOfCelltomove and yOfcelltomove. and I am good to go. I also added 10 to both xOfCellToMove and yOfCellToMove to get mouse over the element vs over left corner of element making it more consistent so 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 itActions 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 itmoveCell.Perform();//run this set of actions