0

I am trying to write a program that loads a webpage in Selenium and then scroll to the bottom of that page. Currently, my program can load the page but cannot scroll to the bottom of it. Below is my full code. Any help will be greatly appreciated, thanks!


from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from bs4 import BeautifulSoup
from selenium.webdriver.chrome.options import Options
from pynput.mouse import Button, Controller


import time

mouse = Controller()

chrome_options = Options()
chrome_options.add_argument("--user-data-dir=chrome-data")

driver = webdriver.Chrome(r"C:\Users\Brian\Downloads\chromedriver.exe", options=chrome_options)
driver.get('https://www.tradingview.com/chart/lUsimB6z/')
time.sleep(5)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")






#open("source.html", "w").write(str(html))
3
  • 1
    It scrolls to the bottom for me. Commented Apr 15, 2020 at 0:27
  • stackoverflow.com/a/61071503/4539709 Commented Apr 15, 2020 at 0:36
  • do you get error ? Did you try to sleep longer? Code works for me. Commented Apr 15, 2020 at 1:19

1 Answer 1

1

I have tried below code and its workingf for me

driver.maximize_window()
wait = WebDriverWait(driver, 10)
driver.get("https://www.tradingview.com/chart/lUsimB6z/")
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

output:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.