简体   繁体   English

Selenium firefox 配置文件下载目录首选项未实现

[英]Selenium firefox profile download directory preference not getting implemented

I have the following code我有以下代码

profile = webdriver.FirefoxProfile()
    profile.set_preference("browser.download.folderList", 2)
    profile.set_preference("browser.download.manager.showWhenStarting", False)
    profile.set_preference("browser.download.dir", os.path.dirname(os.path.realpath(__file__)))
    profile.set_preference("browser.helperApps.neverAsk.openFile", "application/zip")
    driver = webdriver.Firefox(firefox_profile=profile)

But when the zip file gets downloaded it still gets downloaded to my temp dir.但是当 zip 文件被下载时,它仍然会被下载到我的临时目录中。

Any help here will be greatly appreciated!这里的任何帮助将不胜感激!

You need to make two minor modifications as follows:您需要进行以下两个小修改:

os.path.dirname(os.path.realpath(__file__))

with:和:

os.path.abspath(os.path.dirname(__file__))

followed by the line:接着是一行:

profile.set_preference("browser.download.folderList", 2)

Effectively, your code block will be:实际上,您的代码块将是:

profile = webdriver.FirefoxProfile()
    profile.set_preference("browser.download.dir", os.path.abspath(os.path.dirname(__file__)))
    profile.set_preference("browser.download.folderList", 2)
    profile.set_preference("browser.download.manager.showWhenStarting", False)
    profile.set_preference("browser.helperApps.neverAsk.openFile", "application/zip")
    driver = webdriver.Firefox(firefox_profile=profile)

References参考

You can find a detailed discussion on os.path.abspath(os.path.dirname(__file__)) in what does the file variable mean/do?您可以文件变量是什么意思/做什么中找到有关os.path.abspath(os.path.dirname(__file__))的详细讨论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 创建Webdriver后Selenium Firefox配置文件更新下载目录 - Selenium firefox profile update download directory after creating webdriver 使用selenium2library设置自动下载首选项配置文件 - Set auto download preference profile using selenium2library Selenium Firefox 配置文件首选项下载对话框 - Selenium Firefox profile preferences download dialogue box Python Selenium:Firefox set_preference在下载时覆盖文件? - Python Selenium: Firefox set_preference to overwrite files on download? 更改默认配置文件保存目录 - Selenium Firefox - Change default profile saving directory - Selenium Firefox Selenium + Firefox + Python:下载目录问题 - Selenium + Firefox + Python: Download Directory issue Selenium Firefox Python:如何更改下载目录 - Selenium Firefox Python: How to change download directory 这个硒firefox配置文件将文件下载到自定义文件夹有什么问题? - What is wrong with this selenium firefox profile to download file into customized folder? 使用 python selenium 下载文件,使用 firefox 驱动程序正确下载目录 - Download file with python selenium, correct download directory with firefox driver [Selenium] [geckodriver]如何更改firefox配置文件首选项字段,如“security.insecure_field_warning.contextual.enabled” - [Selenium][geckodriver] How to change firefox profile preference fields like “security.insecure_field_warning.contextual.enabled”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM