Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.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
在sekenium python中滚动div的自定义滚动条_Python_Selenium_Web Scraping_Beautifulsoup_Selenium Chromedriver - Fatal编程技术网

在sekenium python中滚动div的自定义滚动条

在sekenium python中滚动div的自定义滚动条,python,selenium,web-scraping,beautifulsoup,selenium-chromedriver,Python,Selenium,Web Scraping,Beautifulsoup,Selenium Chromedriver,我正在使用Selenium从Whatsapp网站上的Whatsapp中刮取联系人。要刮除所有联系人,我需要滚动一个有滚动条的div,但我无法在该div中向下滚动,它会在您向下滚动时加载联系人。 尝试在文档高度上使用javascript.excute,并在元素上滚动。发送密钥PAGE_DOWN也不起作用 from selenium import webdriver from selenium.webdriver.common.keys import Keys from bs4 import Bea

我正在使用Selenium从Whatsapp网站上的Whatsapp中刮取联系人。要刮除所有联系人,我需要滚动一个有滚动条的div,但我无法在该div中向下滚动,它会在您向下滚动时加载联系人。 尝试在文档高度上使用javascript.excute,并在元素上滚动。发送密钥PAGE_DOWN也不起作用

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('window-size=1920x1080')
chrome_options.add_argument('--log-level=3')


driver = webdriver.Chrome(executable_path="driver/chromedriver.exe",options=chrome_options)
driver.get("https://web.whatsapp.com/")
driver.find_element_by_xpath('//*[@title="New chat"]').click() #click on new chat button to open contacts
test2 = driver.find_element_by_xpath("//div[@class='_1c8mz rK2ei']") #this div has an custom scrollbar and should be scrolled down to load more contacts


driver.execute_script('arguments[0].scrollIntoView(true);',test2) #tried this
test2.send_keys(Keys.PAGE_DOWN) # and also this

使用您的代码试用更新问题。添加了带有注释的代码