double_click方法– Selenium Python中的动作链

2021年4月28日19:47:12 发表评论 888 次浏览

Selenium的Python模块旨在通过Python执行自动测试。 ActionChains是一种自动化低级交互的方式, 例如鼠标移动, 鼠标按钮操作, 按键和上下文菜单交互。这对于执行更复杂的操作(例如, 悬停和拖放)很有用。动作链方法由高级脚本使用, 在这些脚本中, 我们需要拖动元素, 单击元素, 双击等。

本文围绕Python Selenium中的Action Chains中的double_click方法展开。方法用于双击一个元素或当前位置。

句法 -

double_click(on_element=None)

Args-

on_element–要单击的元素。如果为None, 则单击当前鼠标位置。

示例–

<input type = "text" name = "passwd" id = "passwd-id" />

要查找元素, 需要使用一种定位策略, 例如,

element = driver.find_element_by_id( "passwd-id" )
element = driver.find_element_by_name( "passwd" )

现在, 可以将double_click方法用作操作链, 如下所示–

double_click(on_element=element)

如何在Selenium Python中使用double_click动作链方法?

展示, double_clickPython中的动作链方法。让我们访问https://www.lsbin.com/并对元素进行操作。

程序–

# import webdriver
from selenium import webdriver
  
# import Action chains 
from selenium.webdriver.common.action_chains import ActionChains
  
# create webdriver object
driver = webdriver.Firefox()
  
# get lsbin.com
driver.get( "https://www.lsbin.com/" )
  
# get element 
element = driver.find_element_by_link_text( "Courses" )
  
# create action chain object
action = ActionChains(driver)
  
# double click the item
action.double_click(on_element = element)
  
# perform the operation
action.perform()

输出–

Selenium Python中的动作链

木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: