【元素操作】鼠标 -ActionChains

actionchains是selenium里面专门处理鼠标相关的操作如:鼠标移动,鼠标按钮

ActionChains 的对象生成操作队列,在没有执行提交 perform() 之前,所有操作只是暂存于队列中,不会实际在页面上操作,需要执行 perform() 时才会实际执行操作

鼠标移动

python 复制代码
    #定位元素
    please_select = driver.find_element(By.CSS_SELECTOR,'.app-address-title')
    #定义动作-鼠标移动
    action =ActionChains(driver)
    action.**move_to_element**(please_select).perform() #注意,必须执行perform方法

单击并且释放

右键点击

click() 点击指定元素,如果没有指定元素,则点击当前鼠标所在位置

python 复制代码
e = driver.find_element_by_id('su')
ActionChains(driver).click(e).perform()

双击

double_click(on_element=None) 双击元素,如果没有指定元素则在当前鼠标位置双击

python 复制代码
e = driver.find_element_by_id('su')
ActionChains(driver).double_click(e).perform()

移动到某元素中心的偏移量的位置

move_to_element_with_offset(to_element, xoffset, yoffset) 将鼠标移动到基于元素的偏移量,偏移量基于鼠标左上角的坐标点

python 复制代码
e = driver.find_element_by_id('su')
ActionChains(driver).move_to_element_with_offset(e, 100, 100).perform()

元素点击

python 复制代码
e = driver.find_element_by_id('su')
ActionChains(driver).context_click(e).perform()

元素输入

python 复制代码
driver.find_element(By.XPATH,'//label[@for="name"]/following-sibling::div//input').send_keys('测试')

元素内容清除

python 复制代码
driver.find_element(By.XPATH,'//label[@for="name"]/following-sibling::div//input').clear()

元素是否显示

相关推荐
CeshirenTester6 小时前
9B 上端侧:多模态实时对话,难点其实在“流”
开发语言·人工智能·python·prompt·测试用例
Starry_hello world6 小时前
Python (2)
python
礼拜天没时间.6 小时前
Docker自动化构建实战:从手工到多阶段构建的完美进化
运维·docker·容器·centos·自动化·sre
ID_180079054736 小时前
Python爬取京东商品库存数据与价格监控
jvm·python·oracle
Cxiaomu7 小时前
【无标题】
自动化
-To be number.wan7 小时前
Python数据分析:时间序列数据分析
开发语言·python·数据分析
Faker66363aaa7 小时前
YOLO13-C3K2-AdditiveBlock:水果质量智能检测系统_3
python
2401_828890648 小时前
实现扩散模型 Stable Diffusion - MNIST 数据集
人工智能·python·深度学习·stable diffusion
jz_ddk8 小时前
[指南] Python循环语句完全指南
开发语言·python·continue·循环·for·while·break
Evand J8 小时前
【Python代码例程】长短期记忆网络(LSTM)和无迹卡尔曼滤波(UKF)的结合,处理复杂非线性系统和时间序列数据
python·lstm·滤波