Firefox can view or modify configuration information by entering: About:config or about:aupport in the address bar.
There are two ways to solve this,
1. Set automatic save download
If checked: Automatically use the same action in the future to process such files
This will not be the next time you download a file of that type.
If you want to modify the settings, you can modify them in the browser options
Such as
This setting is complete, but the browser opened when the program starts does not open in this configuration.
By contrast, the browser opened by Webdriver differs from the manually opened browser, because the browser opened by Webdriver is not opened according to the configuration file set by the browser. If you want to follow the profile, get the profile information before you open it.
Add the following code:
Profile = Webdriver. Firefoxprofile (R"C:\Users\Skyyj\AppData\Roaming\Mozilla\Firefox\Profiles\1rzh6139.default " ) = Webdriver. Firefox (Profile)
2. The second method
is to add configuration information to the code.
by About:config
Find the default configuration via%appdata%\mozilla\firefox\profiles\
Find the MIMETYPES.RDF directory and open it in another way to find the type of file you just saved
MIMETYPES.RDF is present in the configuration path of the above profile
C:\Users\Skyyj\AppData\Roaming\Mozilla\Firefox\Profiles\1rzh6139.default
Find fileextensions= "xlsx"
Nc:value= "Application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Nc:editable= "true"
Nc:fileextensions= "xlsx"
nc:description= "xlsx File" >
You can tell from the file what type of file we need
The code is as follows:
#Profile = Webdriver. Firefoxprofile (r "C:\Users\Skyyj\AppData\Roaming\Mozilla\Firefox\Profiles\1rzh6139.default")Profile =Webdriver. Firefoxprofile ()##设置成0代表下载到浏览器默认下载路径, set to 2 to save to the specified directoryProfile.set_preference ("browser.download.folderList", 2) #the settings here or not are not affected and no effect is found. #profile.set_preference ("browser.download.manager.showWhenStarting", False)Profile.set_preference ("Browser.download.dir"R"C:\Down") Profile.set_preference ("Browser.helperApps.neverAsk.saveToDisk","Application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") #The setting here or not has no effect on finding #profile.set_preference ("Browser.helperApps.alwaysAsk.force", False);Self.driver = Webdriver. Firefox (Profile)
It is recommended to use the second one, so that you do not need to set up a browser, portability is good.
Python webdriver + Firefox File download