HTML部分看起來是這樣的:selenium.common.exceptions.WebDriverException:消息:未找到文件:/路徑/到/文件
...
<form action="/upload/select-single/" method="post" enctype="multipart/form-data">
<input type="hidden" name="csrfmiddlewaretoken" value="U3Uh3EAYWXaWEiNaWC3zcCQutQe8hGM53u4BTx810o08t1GwOfIJI2ayHCFQFySw">
<p>
<label for="id_file_field">File field:</label>
<input id="id_file_field" name="file_field" type="file" multiple="" required="">
</p>
<input id="submit" type="submit" value="submit">
</form>
...
硒測試是這樣的:
...
btn_choose_file = self.browser.find_element_by_id("id_file_field")
# write file path to field
# to check that I really selected the field, I tried btn_choose_file.click() -> and it works
btn_choose_file.send_keys('/path/to/file') # -> THIS is the line which seems to cause the problem
# click submit
self.browser.find_element_by_id("submit").click()
...
不幸的是,當測試執行時出現此錯誤
selenium.common.exceptions.WebDriverException:消息:找不到文件:/ path/to/file
這是由於該文件路徑發送到輸入元素與btn_choose_file.send_keys('/path/to/file')
注意部分:真正的「/路徑/到/文件」是以下
- /用戶/ udos /開發/路徑/ processfile/gpx_data/TEST_DATA /套件001 - VAL波斯基亞沃/伯爾尼納 - 樂Prese.gpx(文件是否存在以及我複製從IDE的路徑)
非常奇怪的行爲。這個測試運行之前,以某種方式我設法打破它...
任何建議可能是什麼原因?
UPDATE
從55.0.2版本降級火狐54.0.1 「固定」 的問題。
見 - 到Firefox的到55.0.2版本(自動發生前2天,因爲我已經配置自動更新)以下geckodriver問題向我指出成一個更新>https://stackoverflow.com/a/45753912/420953
只是一個建議。您可以嘗試從路徑中移除空格。 – Andersson
讚賞!我試着用'/Users/udos/development/trails/processfile/gpx_data/test_data/other/data.gpx',同樣的錯誤:| – udo
你能告訴我們確切的HTML和確切的代碼以及確切的錯誤嗎? – DebanjanB