Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.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
selenium-python中的鼠标滚动模拟_Python_Selenium Webdriver_Selenium Firefoxdriver - Fatal编程技术网

selenium-python中的鼠标滚动模拟

selenium-python中的鼠标滚动模拟,python,selenium-webdriver,selenium-firefoxdriver,Python,Selenium Webdriver,Selenium Firefoxdriver,当我放弃一个网站时,我不得不滚动一个由许多div组成的表格。 我使用以下代码使滚动条移动到末尾 source_element = driver.find_element_by_xpath("//div[4]/div/div[103]/div[2]/div[1]/div[2]") ### Scrollbar element dest_element = driver.find_element_by_xpath("//div[4]/div/div[103]/div[2]/div[1]/div[4]

当我放弃一个网站时,我不得不滚动一个由许多div组成的表格。 我使用以下代码使滚动条移动到末尾

source_element = driver.find_element_by_xpath("//div[4]/div/div[103]/div[2]/div[1]/div[2]") ### Scrollbar element

dest_element = driver.find_element_by_xpath("//div[4]/div/div[103]/div[2]/div[1]/div[4]/span") ### ▼ element
ActionChains(driver).drag_and_drop(source_element, dest_element).perform()
但是问题发生得很快,表中的数据无法正确加载。我试图用selenium-python函数模拟鼠标滚动,但没能实现。除了使用pynput(它可以模拟鼠标功能,但我必须实际将光标放在网页上)之外,是否有其他方法来减慢速度


向下滚动时,它会加载更多的表条目。我也尝试过使用drag n drop by offset,但滚动条不移动,它会抛出MoveTargetOutOfBoundsException

如果您知道元素的位置,则可以使用javascript执行器滚动到元素。我不确定是否有其他解决方案可以缓慢滚动,但如果您的要求是缓慢滚动以加载所有数据,那么您可以尝试滚动到任何元素,等待加载数据,然后滚动到其他元素并重复

JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement scrollto = driver.findElement(By.xpath("//div[4]/div/div[103]/div[2]/div[1]/div[4]/span")); //Find element by xpath and store in variable "Element"     
js.executeScript("arguments[0].scrollIntoView();", scrollto); //This will scroll the page till the element is found

是否要向下滚动页面以触发XHR并加载更多的表条目?很抱歉,我不熟悉XHR,您能解释一下吗?也只有鼠标滚动或点击拖动滚动条,对不起,我没有更新你。当我运行代码时,它没有抛出任何错误,并且在UI中没有执行滚动功能