[英]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)
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.