我正在嘗試向我的 selenium chrome-driver 發送一個 ALT ESC 命令,以將其發送到所有其他視窗的后面
這是相關代碼
from selenium.webdriver import Keys
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)
actions.send_keys(Keys.LEFT_ALT, Keys.ESCAPE)
actions.perform()
這不起作用請幫助
uj5u.com熱心網友回復:
要按組合鍵:
from selenium.webdriver import Keys
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).key_down(Keys.LEFT_ALT).send_keys(Keys.ESCAPE).key_up(Keys.LEFT_ALT).perform()
但似乎這是用于 Windows 的作業系統級鍵組合,這在 selenium 背景關系中不起作用。
Selenium 動作應用于網頁元素,在瀏覽器中觸發一些事件。
uj5u.com熱心網友回復:
在創建瀏覽器會話并打開它之前,您無法將密鑰發送到瀏覽器。
您首先必須初始化驅動程式,打開一些網頁,讓頁面完全加載,然后才嘗試將這些密鑰發送到網頁。
您的代碼可能是這樣的:
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 as EC
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome(executable_path='chromedriver.exe')
wait = WebDriverWait(driver, 20)
actions = ActionChains(driver)
driver.get("https://www.some_url.com/")
wait.until(EC.visibility_of_element_located((By.XPATH, "//div[@class='some class name']")))
actions.send_keys(Keys.LEFT_ALT, Keys.ESCAPE)
actions.perform()
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/422349.html
標籤:
