• 4 鼠标、键盘操作


    WebDriver鼠标、键盘操作

    1 WebDriver操作鼠标方法

    1. context_click()            右击 --> 此方法模拟鼠标右键点击效果
    2. double_click()            双击 --> 此方法模拟双标双击效果
    3. drag_and_drop()            拖动 --> 此方法模拟双标拖动效果
    4. move_to_element()        悬停 --> 此方法模拟鼠标悬停效果
    5. perform()                执行 --> 此方法用来执行以上所有鼠标方法
    

    1.1 鼠标执行 perform()

    在ActionChains类中所有提供的鼠标事件方法,在调用的时候所有的行为都存储在ActionChains类中, 而perform()方法就是执行所有ActionChains中的行为

    必须调用perform()方法才能执行鼠标事件

    1.2 鼠标右键 context_click()

    1. 导包:from selenium.webdriver.common.action_chains import ActionChains
    2. 实例化ActionChains对象:Action=ActionChains(driver)
    3. 调用右键方法:element=Action.context_click(username)
    4. 执行:element.perform()
    

    1.3 鼠标双击 double_click()

    1. 导包:from selenium.webdriver.common.action_chains import ActionChains
    2. 实例化ActionChains对象:Action=ActionChains(driver)
    3. 调用双击方法:element=Action.double_click(username)
    4. 执行:element.perform()
    

    1.4 鼠标拖动 drag_and_drop()

    模拟鼠标拖动动作,选定拖动源元素释放到目标元素

    拖动关键点分析

    1. 源元素   socure=driver.find_element_by_id(xxx)
    2. 目标元素 target=driver.find_element_by_id(xxx)
    3. 调用方法 Action.drag_and_drop(source,target).perform()
    

    1.5 鼠标悬停 move_to_element()

    1. 导包:from selenium.webdriver.common.action_chains import ActionChains
    2. 实例化ActionChains对象:Action=ActionChains(driver)
    3. 调用双击方法:element=Action.move_to_element(element)
    4. 执行:element.perform()
    

    2 常用的键盘操作

    Keys类

    导包:from selenium.webdriver.common.keys import Keys
    
    1. send_keys(Keys.BACK_SPACE)删除键(BackSpace) 
    2. send_keys(Keys.SPACE)空格键(Space) 
    3. send_keys(Keys.TAB)制表键(Tab) 
    4. send_keys(Keys.ESCAPE)回退键(Esc) 
    5. send_keys(Keys.ENTER)回车键(Enter) 
    6. send_keys(Keys.CONTROL,'a') 全选(Ctrl+A) 
    7. send_keys(Keys.CONTROL,'c')复制(Ctrl+C)
    
  • 相关阅读:
    实时黄金价格[自动刷新]
    ping不通动态域名,解决方法
    清除新版阿里旺旺2008自动添加的右键菜单
    MPLS 原理详解
    windows远程桌面缺陷单用户和多用户
    Flash player ActiveX 9错误的解决办法
    关于DHCP原理的讲解
    找回丢失的IE、网上邻居等桌面图标
    xp安装了SP3以后无法更新的解决办法(XP自动更新下载后安装失败)
    ADSL 定时断线重连bat文件 [转载]
  • 原文地址:https://www.cnblogs.com/shibojie/p/11726953.html
Copyright © 2020-2023  润新知