你好:/我目前在我的專案中設定下載檔案夾時遇到問題。
我正在使用 Mac、Pycharm CE、Selenium、Python、Behave 和 Firefox(專案要求)。
我用下載目錄嘗試了這個配置Python Selenium Firefox 問題,但我不確定我做錯了哪一部分。:/ 下載的檔案仍會轉到默認的下載檔案夾。
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
@given("First step")
def step_impl(context):
download_path = "/Users/this/is/the/absolute/path/downloads"
options = Options()
options.set_preference("browser.download.folderList", '2')
options.set_preference("browser.download.manager.showWhenStarting", False)
options.set_preference("browser.download.dir", download_path)
options.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/csv")
context.driver = webdriver.Firefox(options=options)
uj5u.com熱心網友回復:
從如何使用 selenium/firefox/python 切換下載目錄?并使用 Selenium 和 python 將檔案下載到指定位置
我建議嘗試改變
options.set_preference("browser.download.dir", download_path)
options.set_preference("browser.download.dir", '/Users/this/is/the/absolute/path/downloads')
如果路徑中有空格,請嘗試
options.set_preference("browser.download.dir", r'/Users/this/is/the\ space/absolute/path/downloads')
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/506922.html