首页 > 编程知识 正文

js模拟鼠标移动事件,Selenium3自动化测试实战

时间:2023-05-05 08:08:21 阅读:126671 作者:1869

另一方面,使用操作通道如果需要场景一致的操作,则需要操作通道模块。

二、动作通道的使用方法和原理分析动作通道可用于模拟一系列的鼠标操作、鼠标移动、鼠标按钮操作、按钮操作、上下文操作; 鼠标点击、双击、右击、拖动等。

官方网站使用示例:

# actionchainscanbeusedinachainpattern :链式标记menu=driver.find _ element _ by _ CSS _ selector (.nav ' ) )。 hidden _ submenu=driver.find _ element _ by _ CSS _ selector (.nav # submenu1' ) actionchains (驱动器).move or ara then performed.分步书写方法menu=driver.find _ element _ by _ CSS _ selector (.nav ' ) hidden _ su submenu=drremend to_element ) menu ) actions.click(hidden_submenu ) actions.Perrions ) )。操作进入self._actions (类型为list )队列,返回self实例本身,并使用perform方法依次执行3358www.Sina.com/的操作因此,可以继续单击类中的其他操作方法来配置chains,并在perform ()中依次运行。

def __init__(self,driver ) 3360 ' ' createsanewactionchains. args :-driver 3360 thewebdriverinstancewhichichor if self._ driver.W3C : self.W3C _ actions=actionbuilder (driver ) def perform (self ) )。 3360 ' ' performsallstoredactions.' ' if self._ driver.W3C 3360 self.W3C _ actions.perform (else 3360 foractiver队列中的on_element=None ) : ' ' clicksanelement. args 3360 -运行on _ element 3360 the clicksoncurrentmouseposition . if self._ driver.W3C : self.W3C _ actions.pointer _ action.click (self.W3C _ actions.key _ action.pau pau Paul El eon ) 其他操作方法相同Command.CLICK

三、ActionChains包含的方法ActionChains类中的操作方法是解析click(on_element=none ),鼠标左键click_and_hold ) on _ element=

键不松开context_click(on_element=None)点击鼠标右键double_click(on_element=None)双击鼠标左键drag_and_drop(source, target)拖拽指定元素source,到指定target,并松开drag_and_drop_by_offset(source, xoffset, yoffset)拖拽指定元素source到指定的x,y坐标,并松开key_down(value, element=None)按下某个键盘上的键key_up(value, element=None)松开某个键move_by_offset(xoffset, yoffset)鼠标从当前位置移动到某个坐标move_to_element(to_element)鼠标移动到指定元素的中间move_to_element_with_offset(to_element, xoffset, yoffset)鼠标移动到距离指定元素x,y坐标的位置pause(seconds)在指定时间内暂停所有的输入perform()执行链中的所有动作release(on_element=None)在某个元素位置松开鼠标左键reset_actions()清除本地和远程端上已经存储的操作send_keys(*keys_to_send)发送某些键到当前焦点的元素send_keys_to_element(element, *keys_to_send) 发送某些键到指定元素



selenium3.14官网解释如下:

click(on_element=None)点击鼠标左键Clicks an element.Args :on_element: The element to click. If None, clicks on current mouse position.click_and_hold(on_element=None)点击鼠标左键不松开Holds down the left mouse button on an element.Args :on_element: The element to mouse down. If None, clicks on current mouse position.context_click(on_element=None)点击鼠标右键Performs a context-click (right click) on an element.Args :on_element: The element to context-click. If None, clicks on current mouse position.double_click(on_element=None) 双击鼠标左键Double-clicks an element.Args :on_element: The element to double-click. If None, clicks on current mouse position.drag_and_drop(source, target) 拖拽指定元素source,到指定target,并松开Holds down the left mouse button on the source element,then moves to the target element and releases the mouse button.Args :source: The element to mouse down.target: The element to mouse up.drag_and_drop_by_offset(source, xoffset, yoffset) 拖拽指定元素source到指定的x,y坐标,并松开Holds down the left mouse button on the source element,then moves to the target offset and releases the mouse button.Args :source: The element to mouse down.xoffset: X offset to move to.yoffset: Y offset to move to.key_down(value, element=None) 按下某个键盘上的键Sends a key press only, without releasing it.Should only be used with modifier keys (Control, Alt and Shift).Args :value: The modifier key to send. Values are defined in Keys class.element: The element to send keys. If None, sends a key to current focused element.Example, pressing ctrl+c: 举例按下ctrl+cActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform()key_up(value, element=None) 松开某个键Releases a modifier key.Args :value: The modifier key to send. Values are defined in Keys class.element: The element to send keys. If None, sends a key to current focused element.move_by_offset(xoffset, yoffset) 鼠标从当前位置移动到某个坐标Moving the mouse to an offset from current mouse position.Args :xoffset: X offset to move to, as a positive or negative integer.yoffset: Y offset to move to, as a positive or negative integer.move_to_element(to_element) 鼠标移动到指定元素的中间Moving the mouse to the middle of an element.Args :to_element: The WebElement to move to.move_to_element_with_offset(to_element, xoffset, yoffset) 鼠标移动到距离指定元素x,y坐标的位置Move the mouse by an offset of the specified element.Offsets are relative to the top-left corner of the element.Args :to_element: The WebElement to move to.xoffset: X offset to move to.yoffset: Y offset to move to.pause(seconds) 在指定时间内暂停所有的输入Pause all inputs for the specified duration in secondsperform() 执行链中的所有动作Performs all stored actions.release(on_element=None) 在某个元素位置松开鼠标左键Releasing a held mouse button on an element.Args :on_element: The element to mouse up. If None, releases on current mouse position.reset_actions() 清除本地和远程端上已经存储的操作Clears actions that are already stored locally and on the remote endsend_keys(*keys_to_send) 发送某些键到当前焦点的元素Sends keys to current focused element.Args :keys_to_send: The keys to send. Modifier keys constants can be found in the ‘Keys’ class.send_keys_to_element(element, *keys_to_send) 发送某些键到指定元素Sends keys to an element.Args :element: The element to send keys.keys_to_send: The keys to send. Modifier keys constants can be found in the ‘Keys’ class.

参考文章:module-selenium.webdriver.common.action_chains

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。