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(),事件按顺序执行。