I try to download csv file from the Chrome browser launched by selenium.
But
Failed- Path too long error
happens while downloading csv file.
path:
C:/s/d/b
I change path like below, but same error...
/cygdrive/c/s/d/a
\cygdrive\c\s\d\a
\\cygdrive\\c\\s\\d\\a
csv file
20181213171306.csv
chromedriver's path
/cygdrive/c/Users/HOGEHOGE/chromedriver_2.45.exe
Using cygwin, executing python scripts like this below.
python3 C:/s/d/a.py
I set the web driver option like this below.
DIR_DL="C:/s/d/b"
options = Options()
options.add_experimental_option("prefs", {
"download.default_directory":DIR_DL,
})
driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH,chrome_options=options)
driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')
params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': DIR_DL}}
command_result = driver.execute("send_command", params)
Does anyone know how to fix this?
"失敗-パスが長すぎます" is Japanese. It means "Failed- Path too long error".
[Environment]
Windows 10
CYGWIN_NT-10.0 2.11.2
Python 3.6.4
selenium 3.141.0
chrome driver 2.45
chrome browser 71
Try with double slash for the path name:
C:\\d\\s\\b
Try also setting the driver page downloads option on init of webdriver.
driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')
params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': "/path/to/download/dir"}}
command_result = driver.execute("send_command", params)
try set download directory using add_argument
options = Options()
options.add_argument("download.default_directory=C:/s/d/b")
driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH, chrome_options=options)
This error message...
Failed-Path Too Long
...implies that the ChromeDriver failed to interact with the (recently) downloaded file.
As per the discussion Wrong error - "Path Too Long" ... Error should be "File Already Open" this issue is observed when the WebDriver instance ie the driver tries to use the downloaded file too soon.
Error Snapshot:
Induce some wait between the twp steps of:
I changed the CSV Download path to cygwin's to dom's path, then I succeeded to download csv file.
CSV Download's path
/cygdrive/c/Users/CSV_DOWNLOAD_PATH
↓
C:/Users/CSV_DOWNLOAD_PATH
Many thanks for your replies.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.