Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Selenium参数[0]。scroll.to函数第二次不工作_Java_Python_Selenium - Fatal编程技术网

Java Selenium参数[0]。scroll.to函数第二次不工作

Java Selenium参数[0]。scroll.to函数第二次不工作,java,python,selenium,Java,Python,Selenium,我正在使用python for 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_el

我正在使用python for 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);")

我想您可能需要
.scrollIntoView()


如果您需要查看更多代码,请告诉我好的,因此我认为这将起作用,因为我没有收到任何错误,但我需要它滚动\u box2而不是Window它给出了相同的错误。。。我不知道这里是否没有我需要的所有东西。。这是我从selenium导入webdriver从time导入sleep从secrets导入pw从secrets导入电子邮件从selenium导入selenium.webdriver.common.by导入JavaScript得到的结果错误:参数[0]。scrollIntoView不是函数
ht = self.driver.execute_script("""
                arguments[0].scrollIntoView();
                """, scroll_box2)