[英]Right click and perform action using Selenium Python
我想右鍵單擊並使用 Selenium 執行操作,但我無法做到。 我可以右鍵單擊,但它不執行該操作。 我希望任何人都可以幫助我解決這個問題。 下面是代碼。
謝謝...
import openpyxl
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time
option = Options()
option.add_argument("--disable-infobars")
option.add_argument("start-maximized")
option.add_argument("--disable-extensions")
option.add_experimental_option("excludeSwitches", ['enable-automation'])
# Pass the argument 1 to allow and 2 to block
option.add_experimental_option("prefs", {
"profile.default_content_setting_values.notifications": 1
})
driver = webdriver.Chrome(options=option, executable_path='C:\\Users\\Sheik\\Desktop\\web crawling\\chromedriver.exe')
url = "https://www.filepicker.io/api/file/xSc5NYKZQaun3B4LARLZ"
driver.get(url)
save_video = driver.find_element_by_name('media')
action = ActionChains(driver)
action.context_click(save_video).send_keys(Keys.ARROW_DOWN).perform()
使用 pyautogui,您可以按網頁上下文之外的向下箭頭。 下面將選擇上下文減的第一個選項。 嘗試這個:
import openpyxl
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time
import pyautogui
option = Options()
option.add_argument("--disable-infobars")
option.add_argument("start-maximized")
option.add_argument("--disable-extensions")
option.add_experimental_option("excludeSwitches", ['enable-automation'])
# Pass the argument 1 to allow and 2 to block
option.add_experimental_option("prefs", {
"profile.default_content_setting_values.notifications": 1
})
driver = webdriver.Chrome(options=option, executable_path='C:\\Users\\Sheik\\Desktop\\web crawling\\chromedriver.exe')
url = "https://www.filepicker.io/api/file/xSc5NYKZQaun3B4LARLZ"
driver.get(url)
save_video = driver.find_element_by_name('media')
action = ActionChains(driver)
action.context_click(save_video).perform()
time.sleep(1)
pyautogui.press('down')
pyautogui.press('enter')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.