2

I'm using selenium of Java for automation tests and the browser is Firefox.

This is my sample code:

WebElement elem = driver.findElement(By.xpath(".//*[@id='main']/div/div[3]/div[1]/div/div[3]/div/div/div/a"));
Actions action = new Actions(driver);
Actions action2 = action.moveToElement(elem);
action2.perform();

The problem is that "moveToElement" action is triggering auto scrolling event of the page. I want the page to remain as it was before without the scrolling. somebody may know how can I disable this auto scrolling? Thanks.

Arnab Nandy
  • 6,472
  • 5
  • 44
  • 50
user2055886
  • 99
  • 2
  • 10

2 Answers2

3

You can't. WebDriver scrolls elements into view when acting on them.

Ross Patterson
  • 9,527
  • 33
  • 48
1

You can't disable the autoscroll.


Some possible workarounds:

  1. You could try to fire a syntetic mouseover event over your WebElement if that would help your cause.

  2. After the moveToElement(), you could try rescroll to your needed position with window.scrollTo() or for example the Page Up key. This would, obviously, break the mouseover on the element, but maybe it's what you need.

  3. You can position your real mouse cursor over the element via the Robot class. This might get a little tricky, you might need to enter the fullscreen mode with your browser (or use this) and then handle the scroll offsets manually, if there are some.


All depends on your intentions, on what you really need to do with the element and why.

Community
  • 1
  • 1
Petr Janeček
  • 37,768
  • 12
  • 121
  • 145