键盘回车Keys.ENTER
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver import Keys from time import sleep # 实例化驱动对象 driver=webdriver.Chrome() def input_enter(loc): driver.find_element(By.CSS_SELECTOR,loc).send_keys('1',Keys.ENTER) sleep(3) def open_brower(url,loc): # 打开网址 driver.get(url) # 获取颜色 c=input_enter(loc) print(f"颜色是:{c}") # 退出 driver.quit() if __name__ == '__main__': u="https://www.baidu.com" loc="input#kw" open_brower(u,loc)