鼠标操作:双击、右击、悬停、拖拽、按键管理
用户输入操作:单选,多选,select,快捷键
文件上传:JS去修改网页
一.鼠标操作
1. 悬停
# 鼠标悬停(哪个元素) el = browser.find_element(By.XPATH, "//a[contains(text(),'HTML / CSS')]") # 悬停,ActionChains下面的动作方法必须要再机上perform()才能生效 ActionChains(browser).move_to_element(el).perform()
进行元素定位时,先将窗口最大化,防止元素不可见。
import time
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
class TestDemo:
def test_01(self):
with webdriver.Chrome(executable_path='chromedriver96.exe') as browser:
browser.implicitly_wait(10)
browser.get("https://www.runoob.com/html/html-tutorial.html")
# 最大化窗口
browser.maximize_window()
# 鼠标悬停(哪个元素)
el = browser.find_element(By.XPATH, "//a[contains(text(),'HTML / CSS')]")
# 悬停,ActionChains下面的动作方法必须要再机上perform()才能生效
ActionChains(browser).move_to_element(el).perform()
time.sleep(5)
运行后,浏览器效果:
2.双击
# 鼠标悬停(哪个元素) el = browser.f