Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

python - How to set a specific download location in Mozilla - Marionette web driver?

I am having an automation script which worked well before the recent mozilla update. The selenium-python script automates some of my browser actions, and save certain reports (csv) to a defined location.

I have been using selenium 2.53.6, which uses the following code :

profile = webdriver.firefox.firefox_profile.FirefoxProfile()
profile.set_preference('browser.helperApps.neverAsk.saveToDisk',"text/csv, application/pdf,application/octet-stream")
profile.set_preference('browser.download.folderList',2)
profile.set_preference("browser.download.manager.showWhenStarting",False)
profile.set_preference('browser.download.dir','D:Downloads')
driver = webdriver.Firefox(firefox_profile=profile)

Currently I use selenium-python 3.0.1 and Firefox 48. Here I had added the geckodriver path to environment variables and was able to launch firefox using the code below:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

caps = DesiredCapabilities.FIREFOX
caps["marionette"] = True
driver = webdriver.Firefox(capabilities=caps)

I am curious on how to do a profile.set_preference equivalent in firefox-marionette driver. I couldn't find any documentations on it.

Please advise.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can pass profile as well to launch FirefoxDriver as :-

driver = webdriver.Firefox(capabilities=caps, firefox_profile=profile)

You can also set firefox_profile into capabilities as :-

caps["firefox_profile"] = profile
driver = webdriver.Firefox(capabilities=caps)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...