Python 2.7.3
硒3.8.1
铬驱动2.35
Windows 10
我试图从一个网站下载几个不同的文件,但它们有相同的文件名。我想设置“download.prompt_下载“:True,因此当文件下载对话框打开时,我可以通过编程方式键入每个文件名。
但它不起作用(甚至连download.default_目录),它自动下载文件,不打开文件下载对话框,也不保存在我设置的文件夹中。我读过类似的题目,但没用。在from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.chrome.options import Options
import unittest, time, re
class Lalala(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(30)
self.base_url = "http://servicos.dnit.gov.br/dadospnct/ContagemContinua"
self.verificationErrors = []
self.accept_next_alert = True
def test_lalala(self):
options = Options()
options.add_experimental_option("prefs", {
"download.default_directory": r"C:\\Users\rafael.kobayashi\Desktop\Vh\BR101\\",
"download.prompt_for_download": True,
"download.directory_upgrade": True,
"safebrowsing.enabled": True
})
driver = self.driver
driver.get("http://servicos.dnit.gov.br/dadospnct/ContagemContinua")