Чтобы прокрутить страницу к началу в Selenium, вы можете использовать следующие методы:
-
Использование JavaScript Executor:
# Import the necessary modules from selenium import webdriver # Create a WebDriver instance driver = webdriver.Chrome() # Scroll to the top of the page using JavaScript driver.execute_script("window.scrollTo(0, 0);") -
Использование класса Actions:
# Import the necessary modules from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains # Create a WebDriver instance driver = webdriver.Chrome() # Create an instance of ActionChains actions = ActionChains(driver) # Move to the top of the page actions.send_keys_to_element(driver.find_element_by_tag_name('body'), Keys.HOME).perform() -
Использование комбинации клавиш:
# Import the necessary modules from selenium import webdriver from selenium.webdriver.common.keys import Keys # Create a WebDriver instance driver = webdriver.Chrome() # Scroll to the top of the page using the HOME key combination driver.find_element_by_tag_name('body').send_keys(Keys.HOME)