0

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?

enter image description here

enter image description here

"失敗-パスが長すぎます" 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

nobuhiroharada
  • 499
  • 4
  • 13
  • `C:/s/d/b` is real dir name? it is not too long, the problem maybe from your filename. – ewwink Dec 13 '18 at 08:49
  • C:/s/d/b is real dir name. Down load csv file name cannot change, is it? https://stackoverflow.com/questions/38459972/rename-downloaded-files-selenium – nobuhiroharada Dec 13 '18 at 08:53
  • can you post full error message or the screenshot. – ewwink Dec 13 '18 at 09:31
  • Hi @ewwink. Thank you for your reply. I post screen shot. Error logs does not show on the cygwin command line. I don't know how to debug. Any idea? – nobuhiroharada Dec 13 '18 at 09:55

4 Answers4

0

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)
Infern0
  • 2,565
  • 1
  • 8
  • 21
0

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)
ewwink
  • 18,382
  • 2
  • 44
  • 54
0

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 i.e. the driver tries to use the downloaded file too soon.

Error Snapshot:

Failed-Path Too Long


Solution

Induce some wait between the twp steps of:

  • Downloading the csv file.
  • Using the csv file for the next action.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

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.

nobuhiroharada
  • 499
  • 4
  • 13