selenium之鼠标键盘操作
用selenium做自动化,有时候遇到需要用到鼠标操作的情况,比如鼠标移动、鼠标点击等。而selenium给我们提供了一个类来处理这类事件——ActionChains
ActionChains执行原理
调用ActionChains的方法时,不会立即执行,而是会将所有的操作按顺序存放在一个队列里,当你调用perfrom()方法时,按照队列里面的顺序进行执行。其中调用的perform()方法必须放在ActionChains方法最后。
比如
ActionChains(driver).double_click(on_element=None).perform()
ActionChains基本用法
链式写法
menu=driver.find_element_by_name(“a”)
ActionChains(driver).move_to_element(menu).perform()
分步写法
menu=driver.find_element_by_name(“a”)
actions = ActionChains(driver)
actions.move_to_element(menu)
actions.perform()