文件在默认下载文件夹中继续下载

2024-09-28 22:21:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个基本的设置方法:

class BaseTestCase(object):


    def setUp(self): 
        options = webdriver.ChromeOptions()
        options.add_argument("download.default_directory=C:\Users\cverma\Desktop\SOAPProject")

        self.driver = webdriver.Chrome(executable_path=r"C:\chromedriver\chromedriver.exe", chrome_options=options)
        self.driver.maximize_window()
        self.driver.get("https://qa.smartsimpleqa.com")



    def tearDown(self):
        self.driver.quit()

当我在另一个测试中调用此设置方法时。我的文件一直在默认下载文件夹中下载,而我想在单击C:\Users\cverma\Desktop\SOAPProject之后下载我的文件


Tags: 文件方法selfobjectdefdriverchromedriverusers
1条回答
网友
1楼 · 发布于 2024-09-28 22:21:42

尝试以下操作:

chromeOptions = webdriver.ChromeOptions()
prefs = {"download.default_directory" : "C:\Users\cverma\Desktop\SOAPProject\"}
chromeOptions.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(executable_path=r"C:\chromedriver\chromedriver.exe", chrome_options=chromeOptions)

也要注意,如果您将错误的路径设置为“download.default_目录值,您将不会得到异常-chromedriver将只使用下载文件夹作为默认值

相关问题 更多 >