问题描述
重要提示:我正在使用 selenium==4.0.0b3
在使用 selenium-webdriver 上传现有文件的过程中,我进行了测试以发现该文件是否确实存在,以证实我实际上正在上传某些内容并与其保持一致,我的测试代码:
print("Is filepath",os.path.isfile(local_photo_path))
file_inputs[0].send_keys(os.path.abspath(local_photo_path))
Is filepath True
ERROR [_CatchWebDriverError][204] invalid argument: File not found : /tmp/69f9dddf-6f69-490e-9ed3-d9a379e151af.jpg
(Session info: chrome=89.0.4389.90)
selenium.common.exceptions.invalidargumentexception: Message: invalid argument: File not found : /tmp/69f9dddf-6f69-490e-9ed3-d9a379e151af.jpg
(Session info: chrome=89.0.4389.90)
Stacktrace:
#0 0x56282084f2b9 <unkNown>
阅读 Selenium 文档,看来我做对了,这是实际的 selenium 功能:
def send_keys(self,*value) -> None:
"""Simulates typing into the element.
:Args:
- value - A string for typing,or setting form fields. For setting
file inputs,this Could be a local file path.
Use this to send simple key events or to fill out form fields::
form_textfield = driver.find_element(By.NAME,'username')
form_textfield.send_keys("admin")
This can also be used to set file inputs.
::
file_input = driver.find_element(By.NAME,'profilePic')
file_input.send_keys("path/to/profilepic.gif")
# Generally it's better to wrap the file path in one of the methods
# in os.path to return the actual path to support cross OS testing.
# file_input.send_keys(os.path.abspath("path/to/profilepic.gif"))
"""
# transfer file to another machine only if remote driver is used
# the same behavIoUr as for java binding
print('This is send keys')
if self.parent._is_remote:
local_files = list(map(lambda keys_to_send:
self.parent.file_detector.is_local_file(str(keys_to_send)),''.join(map(str,value)).split('\n')))
if None not in local_files:
remote_files = []
for file in local_files:
remote_files.append(self._upload(file))
value = '\n'.join(remote_files)
self._execute(Command.SEND_KEYS_TO_ELEMENT,{'text': "".join(keys_to_typing(value)),'value': keys_to_typing(value)})
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)