zoukankan      html  css  js  c++  java
  • Selenium鼠标模拟事件

    from selenium.webdriver.common.action_chains import ActionChains
     
    原理:调用ActionChains的方法时不会立即执行,会将所有的操作按顺序存放在一个队列里,当调用perform()方法时,队列中的事件会依次执行
    支持链式写法或者分步写法
     
    例:
    #定位到鼠标移动上边的元素
    menu_ele = driver.find_element_by_css_selector('.list_item > li:nth-child(1) > img:nth-child(1)')
    ActionChains(driver).move_to_element(menu_ele).perform()
    #选中子菜单
    sub_menu_ele = driver.find_element_by_css_selector('.base > div:nth-child(3) > a:nth-child(2)')
    sleep(3)
    sub_menu_ele.click()
     
    归纳:
    ActionChains(driver).click(ele).perform()
    鼠标和键盘方法列表:
    perform() 执行链中的所有动作
    click(on_element=None) 单击鼠标左键
    context_click(on_element=None) 点击鼠标右键
    double_click(on_element=None) 双击鼠标左键
    move_to_element(to_element) 鼠标移动到某个元素
    ele.send_keys(keys_to_send) 发送某个词到当前焦点的元素
    ========== 不常用 ==========
    click_and_hold(on_element=None) 点击鼠标左键,不松开
    release(on_element=None) 在某个元素位置松开鼠标左键
    key_down(value, element=None) 按下某个键盘上的键
    key_up(value, element=None) 松开某个键
    drag_and_drop(source, target) 拖拽到某个元素然后松开
    drag_and_drop_by_offset(source, xoffset, yoffset) 拖拽到某个坐标然后松开
    move_by_offset(xoffset, yoffset) 鼠标从当前位置移动到某个坐标
    move_to_element_with_offset(to_element, xoffset, yoffset) 移动到距某个元素(左上角坐标)多少
    距离的位置
    send_keys_to_element(element, keys_to_send) 发送某个键到指定元素

  • 相关阅读:
    fastJson
    关于mybatis “org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)” 错误的问题。
    JVM——自定义类加载器
    NumberFormat数字格式化
    Java BigDecimal详解
    NumberUtils、ArrayUtils和RandomUtils工具类用法
    itext 生成 PDF(二)
    C语言中的可变参数列表
    归并排序--c语言实现
    机器学习实战学习笔记 一 k-近邻算法
  • 原文地址:https://www.cnblogs.com/yimoy/p/14092480.html
Copyright © 2011-2022 走看看