python+selenium点击input上传文件报错selenium.common.exceptions.InvalidArgumentException

browse = driver.find_element_by_id("ffdcFile")
browse.click()

报错:

Traceback (most recent call last):
  File "D:/work/LCPSVN/DCSC/testProject/ffdcparsertest.py", line 19, in <module>
    browse.click()
  File "D:\Program Files\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "D:\Program Files\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "D:\Program Files\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "D:\Program Files\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
  (Session info: chrome=90.0.4430.212)

解决方法:
把element.click()改为 ActionChains(driver).click(element).perform()

browse = driver.find_element_by_id("ffdcFile")
# browse.click()
ActionChains(driver).click(browse).perform()

1.第一种方式是对远程的web driver post 一个请求/session/ s e s s i o n I d / e l e m e n t / sessionId/element/ sessionId/element/id/click 去进行click操作
在这里插入图片描述
2.第二种方式是模拟鼠标操作,对元素进行点击,再post /session/$sessionId/actions

ActionChains是selenium里面专门处理鼠标相关的操作如:鼠标移动,鼠标按钮操作,按键和上下文菜单(鼠标右键)交互。
这对于做更复杂的动作非常有用,比如悬停和拖放。

ActionChains也可以和快捷键结合起来使用,如ctrl,shif,alt结合鼠标一起使用

当你使用actionchains对象方法,行为事件是存储在actionchains对象队列。当你使用perform(),事件按顺序执行。
在这里插入图片描述

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值