
selenium/webdriver/common/touch_actions.py
class TouchActions(object):
"""
Generate touch actions. Works like ActionChains; actions are stored in the
TouchActions object and are fired with perform().
"""TouchActions对象中,并通过perform()触发使用。__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 = driver
self._actions = []perform说明 def perform(self):
"""
Performs all stored actions.
"""
for action in self._actions:
action()API | 说明 |
|---|---|
| 单击 |
| 双击 |
| 在对应x,y坐标按住 |
| 移动到指定位置 |
| 在指定位置释放之前发出的 |
| 滚动到某个位置 |
| 从 |
| 长按 |
| 从屏幕任何地方开始,以x,y的速度(像素/秒)进行移动 |
| 从元素on_element开始,以x,y的速度(像素/秒)移动x,y偏移量 |
# -*- coding:utf-8 -*-
# 作者:NoamaNelson
# 日期:2022/5/24
# 文件名称:selen_touch.py
# 作用:TouchActions类
# 联系:VX(NoamaNelson)
# 博客:https://blog.csdn.net/NoamaNelson
from 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)原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。