Selenium 的鼠标操作

 

from selenium import webdriver
from time import sleep

from selenium.webdriver import ActionChains

driver = webdriver.Firefox()
action = ActionChains(driver)
URL = r"C:\Users\I\Desktop\注册A.html"
driver.get(URL)

ele = driver.find_element_by_css_selector("#userA")
# 鼠标的右键单击
action.context_click(ele).perform()
# 鼠标的左键双击
ele.send_keys("admin")
action.double_click(ele).perform()

sleep(3)
driver.quit()
----------------------------------------------------------------------
----------------------------------------------------------------------
from selenium import webdriver
from time import sleep

from selenium.webdriver import ActionChains

driver = webdriver.Firefox()
action = ActionChains(driver)
URL = r"C:\Users\I\Desktop\drop.html"
driver.get(URL)

# 鼠标的拖拽
source = driver.find_element_by_css_selector("#div1")
target = driver.find_element_by_css_selector("#div2")
# # 需求一:定位红色方框,蓝色方框,将红色方框拖拽覆盖到蓝色方框
action.drag_and_drop(source, target).perform()

# 需求二:定位红色方框,并拖拽到180,120的位置
action.drag_and_drop_by_offset(source, 180, 120).perform()

sleep(3)
driver.quit()

相关文章

转载地址:https://www.cnblogs.com/mini-monkey/p/12104821...
web自动化测试过程中页面截图相对比较简单,可以直接使用sel...
目录前言一、Selenium简介二、浏览器驱动1.浏览器驱动参考2....
一、iframe的含义:iframe是HTML中框架的一种形式,在对界面...
转载请注明出处❤️作者:测试蔡坨坨原文链接:caituotuo.to...
'''##**认识selenium**​**下载:pipinstall...