① 目的:
编写某个模块的自动化脚本方案时,遇到一个问题:想要删除功能,必须长按后才会弹出二次确认弹窗。
② 环境
Python+appium+AndRoid夜神模拟器/IOS真机
③ Python提供的方法
def long_press(self: T, el: Optional['WebElement'] = None, x: Optional[int]
= None, y: Optional[int] = None, duration: int = 1000) -> T:
"""Begin a chain with a press down that lasts `duration` milliseconds
Args:
el: the element to press
x: x coordiate to press. If y is used, x must also be set
y: y coordiate to press. If x is used, y must also be set
duration: Duration to press
Returns:
`TouchAction`: Self instance
"""
self._add_action('longPress', self._get_opts(el, x, y, duration))
return self
④ 使用方法
# 根据元素进行长按(能用元素最好用元素,用坐标可能存在兼容问题)
action = TouchAction(self.driver)
Element =self.driver.find_element_by_xpath('需要长按的元素')
# 5000是设置的长按时间(单位/毫秒)
action.long_press(el).wait(5000).release().perform()
# 根据坐标进行长按
action = TouchAction(self.driver)
action.long_press(x= , y=).wait(5000).release().perform()
X,Y坐标获取方法
白嫖不好,创作不易,各位的点赞就是创作的最大动力。 持续更新,未完待续……