Python Selenium.execute_脚本(“window.scrollTo(0,document.body.scrollHeight);”)不向下滚动

2024-10-01 19:27:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试打开此页面https://justjoin.it/warszawa/devops,然后滚动到页面底部。 我试过用这种方法,但不幸的是它不起作用

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get(
    "https://justjoin.it/warszawa/devops")

close_popup = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.XPATH, '//*[@id="root"]/div[1]/button'))).click()

time.sleep(3)
print('Time over!')

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

Tags: fromhttpsimportsupportbytimedriverselenium
1条回答
网友
1楼 · 发布于 2024-10-01 19:27:10

如果ActionChains适合你,试试看。下面分享一个例子。根据您的要求使用。

from selenium.webdriver import ActionChains

last_element=driver.find_element_by_xpath("{{xpath of last element in the page}}")
a = ActionChains(driver)
a.move_to_element(last_element).perform()

相关问题 更多 >

    热门问题