【问题标题】:Right click and perform action using Selenium Python右键单击并使用 Selenium Python 执行操作
【发布时间】:2019-12-13 16:04:58
【问题描述】:

我想右键单击并使用 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()

【问题讨论】:

    标签: python python-3.x selenium selenium-webdriver web-scraping


    【解决方案1】:

    使用 pyautogui,您可以在网页上下文之外按向下箭头。下面将选择 context minu 的第一个选项。 试试这个:

    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')
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-17
    • 2019-01-08
    • 1970-01-01
    • 2012-01-14
    • 1970-01-01
    • 2018-07-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多