0

So I have a web page where a part of the page is a user list. A user can scroll down this list, but scrolling only works if the mouse pointer is located above this list. Keys like page down or end do not work.

I can locate the element using Selenium and Xpath without any issue, but I don't know how to perform the scrolling in selenium as it only works when the focus is on that specific web element.

I've tried sending keys like page down and end or code like

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

Anybody got any ideas?

Jeffer1980
  • 21
  • 5
  • 1
    Can you share url? – KunduK Nov 05 '19 at 15:28
  • Does this answer your question? [Scroll Element into View with Selenium](https://stackoverflow.com/questions/3401343/scroll-element-into-view-with-selenium) – orde Nov 05 '19 at 16:43
  • Solved it through a workaround by selecting a visible element and then sending an end key through actionchains. – Jeffer1980 Nov 09 '19 at 20:01

2 Answers2

0

Because you mentioned you can locate the element, you could try scrolling to the specific element, instead of using document.body.scrollHeight as your scroll target.

element = driver.find_element(someLocatorHere)

driver.execute_script("arguments[0].scrollIntoView(true);", element)

Hope this helps a bit.

CEH
  • 5,701
  • 2
  • 16
  • 40
0

Scrolling can be achieved in two different ways.

Javascript

 elementId = driver.find_element_by_id("elementId")
 driver.execute_script("arguments[0].scrollIntoView();", elementId)

Action class

actions = ActionChains(driver)
actions.move_to_element(elementId).perform()
SeleniumUser
  • 4,065
  • 2
  • 7
  • 30