gpt4 book ai didi

java - Selenium argument[0].scroll.to 函数第二次不起作用

转载 作者:行者123 更新时间:2023-12-02 08:40:37 24 4
gpt4 key购买 nike

我正在使用 python 作为 selenium,但我需要使用 javascript 函数进行滚动。它就在这里工作。

from selenium import webdriver
from time import sleep
from secrets import pw
from secrets import email
import selenium
from selenium.webdriver.common.by import By

scroll_box = self.driver.find_element_by_xpath('/html/body/div[3]/div/div[3]/div[4]/div[1]/div')
last_ht, ht = 0, 1
while last_ht != ht:
last_ht = ht
sleep(1)
ht = self.driver.execute_script("""
arguments[0].scrollTo(0, arguments[0].scrollHeight);
return arguments[0].scrollHeight;
""", scroll_box)

出于某种原因,这个:

scroll_box2 = self.driver.find_elements_by_class_name('main-view-container__scroll-node')
last_ht, ht = 0, 1
while last_ht != ht:
last_ht = ht
sleep(1)
ht = self.driver.execute_script("""
arguments[0].scrollTo(0, arguments[0].scrollHeight);
return arguments[0].scrollHeight;
""", scroll_box2)

给出这个错误:

Message: javascript error: arguments[0].scrollTo is not a function
为什么?我需要再次滚动,但它不起作用。我对java不太了解,所以我从别人那里复制了这些。有什么建议吗?

最佳答案

你可以尝试使用这个:

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

关于java - Selenium argument[0].scroll.to 函数第二次不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61412434/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com