如何在不在搜索框中发送键的情况下按下键盘按钮?意味着只做 Keys.PAGE_DOWN 而不是 searchbox.send_keys(Keys.PAGE_DOWN)

how to press buttons of keyboard without sending keys in searchbox? means to just do Keys.PAGE_DOWN instead of searchbox.send_keys(Keys.PAGE_DOWN)

python 硒 如何在不在搜索框中发送键的情况下按下键盘按钮? 意味着我只想做 Keys.PAGE_DOWN 而不是 searchbox.send_keys(Keys.PAGE_DOWN) 我想按 send_keys(Keys.PAGE_DOWN) 滚动浏览 instagram 提要 但要做到这一点,我必须在搜索框中发送密钥,但是当我们点击搜索框时会出现一个弹出框 那么我们如何在不输入搜索框的情况下使用键盘上的向下翻页按钮?

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions 
import time
driver = webdriver.Chrome()
driver.get('https://www.instagram.com/')
time.sleep(2)
# PUT YOUR USERNAME
username = driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[1]/div/label/input')
username.send_keys('')
time.sleep(2)
#PUT YOUR PASSWORD
password = driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[2]/div/label/input')
password.send_keys('')
time.sleep(2)
log = driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[3]/button/div')
log.click()
time.sleep(4)
save_info = driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/div/div/div/button')
save_info.click()
time.sleep(2)
notification = driver.find_element_by_xpath('/html/body/div[4]/div/div/div/div[3]/button[2]')
notification.click()
time.sleep(3)
searchbox = driver.find_element_by_class_name("x3qfX")
for i in range(0,5):
    searchbox.send_keys(Keys.PAGE_DOWN)
    time.sleep(1)

see this screenshot there is RECENTS popup box

您不需要将 Keys.PAGE_DOWN 发送到搜索框。
改为这样做:

driver.find_element_by_tag_name('body').send_keys(Keys.PAGE_DOWN)

这应该像您通过按键盘上的 Page Down 键手动滚动页面一样向下滚动。