6

I want to scroll the left nav bar (which shows the job list) to the bottom using python, selenium and chromedriver. I tried using:

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

But nothing happened. I'm new to web automation, please let me know if you need anything.

P.S. Page source

Page image

thmspl
  • 2,437
  • 3
  • 22
  • 48
Mahesh Gupta
  • 135
  • 1
  • 13
  • It is a common issue to scroll inside an HTML element. Check out these answers:https://stackoverflow.com/questions/27189182/how-to-scroll-a-specific-div-using-selenium-webdriver-with-java BTW, you don't need to scroll in order to act on an element, if you need to load new list elements you may just execute the specific script/function in your page (to find this function you have to use brower's developer tool). – furkanayd Dec 18 '19 at 07:57
  • Thank you furkanayd. Can you please guide me how to find those particular scripts/functions? The above question link was helpful for me though. – Mahesh Gupta Dec 18 '19 at 16:31

1 Answers1

2

This is the last element job list in the left nav bar:

(//li[contains(@class, 'PaEvOc')])[last()]

To achieve scroll to bottom left nav use .location_once_scrolled_into_view:

element = driver.find_element_by_xpath("(//li[contains(@class, 'PaEvOc')])[last()]")
element.location_once_scrolled_into_view
frianH
  • 7,295
  • 6
  • 20
  • 45
  • 1
    How did you manage to find 'PaEvOc' ? I tried to inspect that page again, and could not find `PaEvOc` or `gws-horizon-textlists__li-ed` on that page (I presume this is how people found that last element in the past). I am attempting the same exercise and am also stuck similarly to the original poster – Joe J. Jul 07 '20 at 03:14