mouse and keyboard actions in detail

from selenium import webdriver
from selenium.webdriver.common.by import By
import time

# clickAndHold
with webdriver.Chrome() as driver:
    print('打开百度')
    driver.get("https://www.baidu.com")

    # Store 'google search' button web element
    print('选中链接并存储')
    searchLink = driver.find_element(By.LINK_TEXT, "地图")

    # Perform click-and-hold action on the element
    print('鼠标移动到该元素,然后在给定元素的中间单击(不释放).')
    webdriver.ActionChains(driver).click_and_hold(searchLink).perform()
    print('看到地图变色')
    time.sleep(10)
    print('会话结束,关闭浏览器')

# contextClick
with webdriver.Chrome() as driver:
    print('打开百度')
    driver.get("https://www.baidu.com")

    # Store 'google search' button web element
    print('选中链接并存储')
    searchLink = driver.find_element(By.LINK_TEXT, "地图")

    # Perform click-and-hold action on the element
    print('将鼠标移动到元素的位置, 然后在给定元素执行上下文点击(右键单击).')
    webdriver.ActionChains(driver).context_click(searchLink).perform()
    print('查看效果')
    time.sleep(10)
    print('会话结束,关闭浏览器')

# doubleClick
with webdriver.Chrome() as driver:
    print('打开百度')
    driver.get("https://www.baidu.com")

    # Store 'google search' button web element
    print('选中链接并存储')
    searchLink = driver.find_element(By.LINK_TEXT, "地图")

    # Perform click-and-hold action on the element
    print('移动到该元素, 并在给定元素的中间双击.')
    webdriver.ActionChains(driver).double_click(searchLink).perform()
    print('查看效果')
    time.sleep(10)
    print('会话结束,关闭浏览器')

# moveToElement
with webdriver.Chrome() as driver:
    print('打开百度')
    driver.get("https://www.baidu.com")

    # Store 'google search' button web element
    print('选中链接并存储')
    searchLink = driver.find_element(By.LINK_TEXT, "地图")

    # Perform click-and-hold action on the element
    print('鼠标移到元素的中间. 执行此操作时, 该元素也会滚动到视图中.')
    webdriver.ActionChains(driver).move_to_element(searchLink).perform()
    print('查看效果')
    time.sleep(10)
    print('会话结束,关闭浏览器')

# moveByOffset
with webdriver.Chrome() as driver:
    print('打开百度')
    driver.get("https://www.baidu.com")

    # Store 'google search' button web element
    print('选中链接并存储')
    searchLink = driver.find_element(By.LINK_TEXT, "地图")
    xOffset = 100
    yOffset = 100
    # Perform click-and-hold action on the element
    print('将鼠标从其当前位置(或0,0)移动给定的偏移量')
    webdriver.ActionChains(driver).move_by_offset(xOffset, yOffset).perform()
    print('查看效果')
    time.sleep(10)
    print('会话结束,关闭浏览器')

# dragAndDrop
with webdriver.Chrome() as driver:
    print('打开拖拽示例网址')
    driver.get("https://crossbrowsertesting.github.io/drag-and-drop")

    # Store 'box A' as source element
    sourceEle = driver.find_element(By.ID, "draggable")
    # Store 'box B' as source element
    targetEle = driver.find_element(By.ID, "droppable")
    # Performs drag and drop action of sourceEle onto the targetEle
    print('首先在源元素上单击并按住,然后移动到目标元素的位置后释放鼠标')
    webdriver.ActionChains(driver).drag_and_drop(sourceEle, targetEle).perform()
    print('查看效果')
    time.sleep(10)
    print('会话结束,关闭浏览器')

# dragAndDropBy
with webdriver.Chrome() as driver:
    print('打开拖拽示例网址')
    driver.get("https://crossbrowsertesting.github.io/drag-and-drop")

    # Store 'box A' as source element
    sourceEle = driver.find_element(By.ID, "draggable")
    # Store 'box B' as source element
    targetEle = driver.find_element(By.ID, "droppable")
    targetEleXOffset = targetEle.location.get("x")
    targetEleYOffset = targetEle.location.get("y")
    print('首先在源元素上单击并按住, 移至给定的偏移量后释放鼠标')
    # Performs dragAndDropBy onto the target element offset position
    webdriver.ActionChains(driver).drag_and_drop_by_offset(
        sourceEle, targetEleXOffset, targetEleYOffset).perform()
    print('查看效果')
    time.sleep(10)
    print('会话结束,关闭浏览器')

# release
with webdriver.Chrome() as driver:
    print('打开拖拽示例网址')
    driver.get("https://crossbrowsertesting.github.io/drag-and-drop")

    # Store 'box A' as source element
    sourceEle = driver.find_element(By.ID, "draggable")
    # Store 'box B' as source element
    targetEle = driver.find_element(By.ID, "droppable")
    print('释放按下的鼠标左键. 如果WebElement转移了, 它将释放给定WebElement上按下的鼠标左键.')
    # Performs dragAndDropBy onto the target element offset position
    webdriver.ActionChains(driver).click_and_hold(sourceEle).move_to_element(targetEle).perform()
    # Performs release event
    webdriver.ActionChains(driver).release().perform()
    print('查看效果')
    time.sleep(10)
    print('会话结束,关闭浏览器')

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ava实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),可运行高分资源 Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值