如何在 IE 模式下接受来自 Edge 的弹出消息 Python - Selenium

问题描述 投票:0回答:1

当我尝试在 IE 模式下从 Edge 下载文件时,我收到此下载的确认消息,但我不知道如何克服它,它不允许我接受 ALT + G 等命令,它不允许文件是否存在并不重要,因为重要的是克服接受(保存)这一步骤,或者如果失败,则需要进行一些允许在没有此消息的情况下下载的配置。

enter image description here

from selenium import webdriver
driver = webdriver.Ie(service=Service(executable_path="C:\IEDriverServer_Win32_4.14.0\IEDriverServer.exe"))
driver.get("https://www.winrar.es/descargas")
driver.find_element(By.XPATH, "//*[contains(text(),"Descargue WinRAR ahora")]").click()

我已经尝试发送

actions = ActionChains(driver)
actions.key_down(Keys.ALT).send_keys('g').key_up(Keys.ALT).perform()

但是不行,就像直接通过js发送一样也不行

python selenium-webdriver internet-explorer microsoft-edge
1个回答
0
投票

恐怕您无法仅使用 Selenium 命令与下载弹出窗口进行交互。 Selenium 无法处理这个弹出窗口。您需要查看 AutoIT 等工具来处理此弹出窗口。

如果您想简单地跳过此弹出窗口,您可以尝试 Wget:

import os

from selenium import webdriver
from selenium.webdriver.common.by import By


ie_options = webdriver.IeOptions()
ie_options.attach_to_edge_chrome = True
ie_options.ignore_protected_mode_settings = True
ie_options.edge_executable_path = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"

driver = webdriver.Ie(options=ie_options)

# We directly go to second URL to avoid auto-download, and avoid the popup.
driver.get("https://www.winrar.es/descargas/101/descargar-winrar-para-windows-x64-en-ingles")
# Get download URL
download = driver.find_element(By.XPATH, "//*[@id='subcontent']/table/tbody/tr[1]/td/a")
url_download = download.get_attribute("href")
# Download the file with Wget
os.system('cmd /c C:\\Windows\\System32\\wget.exe -P c:\\temp --no-check-certificate ' + url_download)
© www.soinside.com 2019 - 2024. All rights reserved.