MoveToElement actions changed is Selenium 4

39 views Asked by At

I have a Selenium project and used Selenium-Webdriver 3.141 and just upgraded to latest Selenium 4 Webdriver.

Before the upgrade I had the following code which helped me moving an element on the page(Canvas).

  var pageTopElement = m_driver.FindElement(pageTopElementBy);

        actions
            .MoveToElement(pageTopElement, 0, 0, MoveToElementOffsetOrigin.TopLeft)
            .MoveByOffset(referenceElementLocation.X + (int)startingPoint.X, referenceElementLocation.Y + (int)startingPoint.Y)
            .ClickAndHold()
            .MoveByOffset((int)offSetPoint.X, (int)offSetPoint.Y)
            .Release()
            .Build()
            .Perform();

In Selenium 4, the MoveToElement has been changed so it gets only the 2 first parameteres. And now it looks like that:

       var pageTopElement = m_driver.FindElement(pageTopElementBy);

        actions
            .MoveToElement(pageTopElement, 0, 0)
            .MoveByOffset(referenceElementLocation.X + (int)startingPoint.X, referenceElementLocation.Y + (int)startingPoint.Y)
            .ClickAndHold()
            .MoveByOffset((int)offSetPoint.X, (int)offSetPoint.Y)
            .Release()
            .Build()
            .Perform();

But now, I'm getting an error: move target out of bounds.

I have tried adding an additional lines before the actions but it didn't work

   IJavaScriptExecutor js = (IJavaScriptExecutor)m_driver;
   js.ExecuteScript("arguments[0].scrollIntoView();", pageTopElement);
0

There are 0 answers