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()
滑动解锁
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()
未经允许不得转载:445IT之家 » python 用selenium操作鼠标(悬停、右击、双击、滑动解锁