zoukankan      html  css  js  c++  java
  • Action Chains类 使用鼠标操作使用方法

    1.context.click() 鼠标双击
    2.double_click() 鼠标双击
    3.drag_and_drop() 鼠标拖动
    4..move_to_element() 鼠标悬停在一个元素上
    5.click_and_hold() 按下鼠标左键在一个元素上,release()释放

    1.context_click()鼠标右击

    1 #--coding:utf-8--
    2 from selenium import webdriver
    3 from selenium.webdriver.common.action_chains import ActionChains
    4 driver = webdriver.Chrome()
    5 driver.maximize_window()
    6 driver.get("http://www.baidu.com")
    7 element = driver.find_element_by_link_text('hao123')
    8 ActionChains(driver).context_click(element).perform()

    2.double_click()鼠标双击

    1 #--coding:utf-8--
    2 from selenium import webdriver
    3 from selenium.webdriver.common.action_chains import ActionChains
    4 driver = webdriver.Chrome()
    5 driver.maximize_window()
    6 driver.get("http://www.baidu.com")
    7 element = driver.find_element_by_link_text('hao123')
    8 ActionChains(driver).double_click(element).perform()

    3.drag_and_drop() 鼠标拖动

    1 #--coding:utf-8--
    2 from selenium import webdriver
    3 from selenium.webdriver.common.action_chains import ActionChains
    4 driver = webdriver.Chrome()
    5 driver.maximize_window()
    6 driver.get("http://www.baidu.com")
    7 source = driver.find_element_by_link_text('新闻')
    8 target = driver.find_element_by_id('kw')
    9 ActionChains(driver).drag_and_drop(source,target).perform()

    4.move_element_to()

    1 #--coding:utf-8--
    2 from selenium import webdriver
    3 from selenium.webdriver.common.action_chains import ActionChains
    4 import time
    5 driver = webdriver.Chrome()
    6 driver.maximize_window()
    7 driver.get("http://www.baidu.com")
    8 more_products = driver.find_element_by_link_text('更多产品')
    9 ActionChains(driver).move_to_element(more_products).perform()
    10 driver.find_element_by_link_text('音乐').click()
    11 time.sleep(3)
    12 driver.quit()

    5.click_and_hold()按下鼠标左键在一个元素上,release()释放

    1 #--coding:utf-8--
    2 from selenium import webdriver
    3 from selenium.webdriver.common.action_chains import ActionChains
    4 import time
    5 driver = webdriver.Chrome()
    6 driver.maximize_window()
    7 driver.get("http://www.baidu.com")
    8 element = driver.find_element_by_link_text('新闻')
    9 ActionChains(driver).click_and_hold(element).perform()
    10 ActionChains(driver).release(element).perform()
    11 time.sleep(3)
    12 driver.quit()

    注:perform():执行所有 ActionChains 中存储的行为

  • 相关阅读:
    pipenv install
    git删除缓存区中文件
    zsh切换bash bash切换zsh
    Mac下安装allure
    Linux基础命令之tail动态显示日志文件时关键字有颜色、高亮显示
    CentOS添加tailf命令
    阿里云服务器添加安全组,允许url+端口访问
    pytest中用例的识别与运行
    [转] 使用webpack4提升180%编译速度
    [转] 默认分包策略
  • 原文地址:https://www.cnblogs.com/zhen9436/p/14012115.html
Copyright © 2011-2022 走看看