如何在Python中使用Selenium控制WINDOW下载Dialga-box的打开/保存/取消

时间:2019-05-22 06:15:10

标签: python selenium internet-explorer selenium-webdriver dialog

似乎下载对话框不是DOM,因此

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

dr = webdriver.Ie(executable_path="IE.exe")

# EXAMPLE  -- download ZIP Jun 20,2018
dr.get('https://usda.library.cornell.edu/concern/publications/j098zb09z?locale=en')
download_CSV =driver.dr.dr.find_element_by_css_selector('#j6731631h > div').click()

# Find the download dialog-box and click save but no function in python selenium.

如何通过什么样的库在python中应用这些功能?

using System.Windows.Forms;

SendKeys.SendWait(@"C:\Users\Public\Pictures\Sample Pictures\Dock.jpg");
SendKeys.SendWait(@"{Enter}");

CheryJose的解释清楚地表明对话框不是DOM之一

Selenium Web Driver Cancelling Firefox Downloads

如何与Python中的那些脚本结合? 控制下载对话框-这些目录并单击确定

1 个答案:

答案 0 :(得分:1)

请参考this thread,您可以使用send_keys方法和Keys.ENTER:

from selenium.webdriver.common.keys import Keys
driver.find_element_by_id("element_id").send_keys(Keys.ENTER)

以下是一些相关文章,您可以参考它们:

Python selenium.webdriver.common.keys.Keys.ENTER() Examples

ENTER key press using Selenium WebDriver with python