在Selenium、Chrome和Python中向下滚动一定量

在Selenium、Chrome和Python中向下滚动一定量,python,selenium,google-chrome,webdriver,Python,Selenium,Google Chrome,Webdriver,我最近从一个非常旧的Chromedriver版本升级到了新的Chromedriver版本,这给我以前的代码带来了很多问题,其中一个更令人恼火的问题是.scroll命令现在似乎产生了错误,例如: scroll_obj=selenium.webdriver.common.touch_actions.TouchActions(driver) scroll_obj.scroll(0,scroll_value) scroll_obj.perform() 它会产生以下错误: Web

我最近从一个非常旧的Chromedriver版本升级到了新的Chromedriver版本,这给我以前的代码带来了很多问题,其中一个更令人恼火的问题是.scroll命令现在似乎产生了错误,例如:

    scroll_obj=selenium.webdriver.common.touch_actions.TouchActions(driver)
    scroll_obj.scroll(0,scroll_value)
    scroll_obj.perform()
它会产生以下错误:

WebDriverException:消息:未知命令:在W3C模式下无法调用非W3C标准命令

如果我只是向下滚动一个固定的数量,而不是滚动到特定的文档高度,是否可以执行类似的操作?我只能找到向下滚动到设置位置的Javascript解决方案。

这将有助于您:

horizontal_scroll = 0

vertical_scroll = 1000

driver.execute_script("window.scrollBy(horizontal_scroll , vertical_scroll );")
**To scroll down the web page by pixel.**

JavascriptExecutor js = (JavascriptExecutor) driver;
// This  will scroll down the page by  1000 pixel vertical      
js.executeScript("window.scrollBy(0,1000)");

**To scroll down the web page by the visibility of the element.**

JavascriptExecutor js = (JavascriptExecutor) driver;
//Find element by link text and store in variable "Element"             
 WebElement Element = driver.findElement(By.linkText("Linux"));
 //This will scroll the page till the element is found      
 js.executeScript("arguments[0].scrollIntoView();", Element);


**To scroll down the web page at the bottom of the page.**
 JavascriptExecutor js = (JavascriptExecutor) driver;
 js.executeScript("window.scrollTo(0, document.body.scrollHeight)");