本文主要是介绍selenium源码通读·11 |webdriver/common/touch_actions.py-TouchActions类分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
·11 |webdriver/common/touch_actions.py-TouchActions类分析
- 1 源码路径
- 2 功能说明
- 3 `__init__`说明
- 4 `perform`说明
- 5 所有API
- 6 实例说明
1 源码路径
selenium/webdriver/common/touch_actions.py
2 功能说明
class TouchActions(object):"""Generate touch actions. Works like ActionChains; actions are stored in theTouchActions object and are fired with perform()."""
- 模拟移动端操作;
- 类似ActionChains一样;
- 动作存储在
TouchActions
对象中,并通过perform()
触发使用。
3 __init__
说明
def __init__(self, driver):"""Creates a new TouchActions object.:Args:- driver: The WebDriver instance which performs user actions.It should be with touchscreen enabled."""self._driver = driverself._actions = []
- 创建新的TouchActions对象;
- 执行用户操作的WebDriver实例,即传入driver。
4 perform
说明
def perform(self):"""Performs all stored actions."""for action in self._actions:action()
- 执行所有存储的操作。
5 所有API
API | 说明 |
---|---|
tap(self, on_element) | 单击 |
double_tap(self, on_element) | 双击 |
tap_and_hold(self, xcoord, ycoord) | 在对应x,y坐标按住 |
move(self, xcoord, ycoord) | 移动到指定位置 |
release(self, xcoord, ycoord) | 在指定位置释放之前发出的tap_and_hold 命令 |
scroll(self, xoffset, yoffset) | 滚动到某个位置 |
scroll_from_element(self, on_element, xoffset, yoffset) | 从on_element 元素开始,触摸并滚动到x,y偏移量 |
long_press(self, on_element) | 长按 |
flick(self, xspeed, yspeed) | 从屏幕任何地方开始,以x,y的速度(像素/秒)进行移动 |
flick_element(self, on_element, xoffset, yoffset, speed) | 从元素on_element开始,以x,y的速度(像素/秒)移动x,y偏移量 |
6 实例说明
# -*- coding:utf-8 -*-
# 作者:NoamaNelson
# 日期:2022/5/24
# 文件名称:selen_touch.py
# 作用:TouchActions类
# 联系:VX(NoamaNelson)
# 博客:https://blog.csdn.net/NoamaNelsonfrom time import sleep
from selenium import webdriver
from selenium.webdriver import TouchActions"""
1、打开chrome,输入百度网址
2、搜索框输入“NoamaNelson”,点击搜索
3、上划页面到底部,点击“下一页”
"""
option = webdriver.ChromeOptions()
option.add_experimental_option('w3c', False)
driver = webdriver.Chrome(options=option)
driver.maximize_window()
driver.implicitly_wait(3)driver.get("https://www.baidu.com")
el = driver.find_element_by_id("kw")
el_search = driver.find_element_by_id("su")
el.send_keys("NoamaNelson")
action = TouchActions(driver)
action.tap(el_search)
action.scroll_from_element(el, 0, 3000)
action.perform()
driver.find_element_by_css_selector('#page > div > a.n').click()
sleep(3)
『全栈测试技术,分享,共勉,共进,提升』

这篇关于selenium源码通读·11 |webdriver/common/touch_actions.py-TouchActions类分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!