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