3

I am trying to scroll Up in a whats app conversation so I record the entire chat (into csv).

chrome_options = Options()
chrome_options.add_argument("--user-data-dir=chrome-data") #saves login 
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get('https://web.whatsapp.com/')
#choose converstaion
#scroll to top not working

Here is what I tried but it didn't work, Ideally I will run headless so I prefer not to use pyautogui

def scroll_to_top():
    driver.execute_script("window.scrollTo(0, -document.body.scrollHeight);")
    time.sleep(4)

#driver.execute_script("window.scrollTo(0, 0);")
#bd = driver.find_element_by_xpath('//body')
#bd.click()
#bd.send_keys(Keys.CONTROL+Keys.HOME) #throws element not interact-able

Any help is appreciated

hadesfv
  • 386
  • 4
  • 18

1 Answers1

2

Please use below code to scroll to top of your page

solution 1 :

driver.execute_script("window.scrollTo(0, 220)")

solution 2 :

from selenium.webdriver.common.keys import Keys
html = driver.find_element_by_tag_name('html')
html.send_keys(Keys.PAGE_UP) 
SeleniumUser
  • 4,065
  • 2
  • 7
  • 30