说明:本篇博客基于selenium 4.1.0
ActionChains说明
ActionChains都是selenium的一个模块,提供模拟鼠标动作和键盘动作的功能
ActionChains使用方法
# 步骤1:实例化一个ActionChains动作容器
actions = ActionChains(driver, 250)
# 步骤2:往动作容器中依次添加动作
actions.click(ele_click) # 调用的动作都会添加到动作容器中
actions.click_and_hold(ele_drag).release(ele_item2) # 链式添加动作。每个动作返回值为容器对象,因此支持链式连续添加
# 步骤3:执行动作
actions.perform()
ActionChains动作列表
import time
from selenium import webdriver
from selenium.webdriver import ActionChains, Keys
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.implicitly_wait(5)
# 创建动作容器
actions = ActionChains(driver, 250)
# 等待
n = 3
actions.pause(n) # 插入在动作中,强制暂停n秒
# 鼠标点击
driver.get('http://sahitest.com/demo/clicks.htm')
ele_click = driver.find_ele

最低0.47元/天 解锁文章
1274

被折叠的 条评论
为什么被折叠?



