一、悬停、右击、双击文章来源:https://www.toymoban.com/news/detail-523137.html
from time import sleep
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
# 1. 获取浏览器
driver = webdriver.Chrome()
# 2. 打开浏览器 # 输入自己的url
driver.get("")
# 3. 获取ActionChains 对象 导包
action = ActionChains(driver)
# 查找注册按钮
el = driver.find_element(By.CSS_SELECTOR, "button")
sleep(2)
# 3.1、调用悬停方法
action.move_to_element(el).perform()
# 3.2、 右击
username = driver.find_element(By.CSS_SELECTOR,"#user")
action.context_click(username).perform()
# 3.3、双击
username = driver.find_element(By.CSS_SELECTOR,"#user")
username.send_keys("admin")
sleep(3)
action.double_click(username).perform()
# 4. 关闭浏览器
sleep(3)
driver.quit()
二、拖拽文章来源地址https://www.toymoban.com/news/detail-523137.html
from time import sleep
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
# 1. 获取浏览器
driver = webdriver.Chrome()
# 2. 打开浏览器 # 输入自己的url
driver.get("")
sleep(3)
# 3. 获取ActionChains 对象 导包
action = ActionChains(driver)
# 拖拽(用于 滑动解锁)
div1 = driver.find_element(By.CSS_SELECTOR, "#div1")
div2 = driver.find_element(By.CSS_SELECTOR, "#div2")
action.drag_and_drop(div1, div2).perform()
# 4. 关闭浏览器
sleep(3)
driver.quit()
到了这里,关于Selenium - 如何操作鼠标进行悬停、右击、双击、拖拽?的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!