Failed-Path Too Long error after downloading csv file using ChromeDriver and Chrome Browser launched by Selenium through cygwin in Python

戏子无情 提交于 2019-12-11 15:36:46

问题


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


回答1:


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)



回答2:


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)



回答3:


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:


Solution

Induce some wait between the twp steps of:

  • Downloading the csv file.
  • Using the csv file for the next action.



回答4:


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.



来源:https://stackoverflow.com/questions/53757965/failed-path-too-long-error-after-downloading-csv-file-using-chromedriver-and-chr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!