Java教程

Selenium 的鼠标操作

本文主要是介绍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()
这篇关于Selenium 的鼠标操作的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!