如何在硒中模拟触摸屏?

垫料

我正在尝试创建一个机器人,该机器人必须单击一些无法识别鼠标单击但可以识别触摸的元素,我在网上进行了一些搜索,找到了一种模拟触摸事件的方法。我写了这个

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.touch_actions import TouchActions

user_agent = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16"
profile = webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override", user_agent)
driver = webdriver.Firefox(profile)
driver.set_window_size(400, 800)

WebDriverWait(driver, 10).until(lambda d: d.find_element_by_css_selector(".qJfNm").is_displayed())
element = driver.find_element_by_css_selector(".qJfNm")
touchactions = TouchActions(driver)
touchactions.tap(element)

并且不会引发错误,但是它不起作用,屏幕上没有任何变化。根据文档https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/interactions/touch/TouchActions.html

tap方法可模拟mouse clicks并没有touchscreen events,所以我想知道如果有一个模拟的方式touchscreen eventsselenium,或这是正确的方式和我错了,这样做。

我也尝试过写touchactions.tap(element).perform()而不是touchactions.tap(element)

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.touch_actions import TouchActions

user_agent = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16"
profile = webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override", user_agent)
driver = webdriver.Firefox(profile)
driver.set_window_size(400, 800)

WebDriverWait(driver, 10).until(lambda d: d.find_element_by_css_selector(".qJfNm").is_displayed())
element = driver.find_element_by_css_selector(".qJfNm")
touchactions = TouchActions(driver)
touchactions.tap(element).perform()

但是它引发了这个错误

Traceback (most recent call last):
  File "C:/Users/mcara/OneDrive/Desktop/instagram bot mobile/instagram_bot_mobile.py", line 57, in <module>
    touchactions.tap(element).perform()
  File "C:\Users\mcara\PycharmProjects\1\venv\lib\site-packages\selenium\webdriver\common\touch_actions.py", line 47, in perform
    action()
  File "C:\Users\mcara\PycharmProjects\1\venv\lib\site-packages\selenium\webdriver\common\touch_actions.py", line 57, in <lambda>
    Command.SINGLE_TAP, {'element': on_element.id}))
  File "C:\Users\mcara\PycharmProjects\1\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\mcara\PycharmProjects\1\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: POST /session/71d75201-9012-46a1-9c6e-1c720dd332ce/touch/click did not match a known command

而且不明白为什么。

我使用gekodriverpython 3windows 10

西尔维罗

有趣的问题!也许在这种情况下点击还不够,我们需要在chrome选项旁边使用double_tab :)

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

mobile_emulation = { "deviceName": "Nexus 6" }

chrome_options = Options()
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)

driver = webdriver.Chrome(chrome_options = chrome_options)
    WebDriverWait(driver, 10).until(lambda d: d.find_element_by_css_selector(".qJfNm").is_displayed())
    element = driver.find_element_by_css_selector(".qJfNm")
    touchactions = TouchActions(driver)
    touchactions.double_tab(element)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在ogl中获取触摸屏点的坐标?

来自分类Dev

如何在不使用触摸屏的情况下模拟触摸事件

来自分类Dev

如何模拟鼠标右键在触摸屏上的单击?

来自分类Dev

如何模拟鼠标右键在触摸屏上的单击?

来自分类Dev

在Chrome DevTools中模拟触摸屏时如何检查元素?

来自分类Dev

如何在Internet Explorer 11上的Windows 8.1中检测触摸屏?

来自分类Dev

如何在unity3d中创建触摸屏android滚动?

来自分类Dev

如何在gnome 3.14中禁用边缘触摸屏手势

来自分类Dev

如何在Internet Explorer 11上的Windows 8.1中检测触摸屏?

来自分类Dev

如何在Eclipse中将触摸屏左右分开?

来自分类Dev

如何在Ubuntu 18.04上永久禁用触摸屏

来自分类Dev

如何从脚本中检测触摸屏设备?

来自分类Dev

缺少“模拟触摸屏”选项,“设备模拟”不提供任何触摸屏响应

来自分类Dev

如何使用触摸屏绘制?

来自分类Dev

如何禁用我的触摸屏

来自分类Dev

如何删除触摸屏硬件

来自分类Dev

如何捕获触摸屏事件?

来自分类Dev

在iOS Safari中模拟/触发选择框(可能带有触摸屏)

来自分类Dev

如何在C#WPF中在触摸屏上识别输入指针是鼠标还是手指?

来自分类Dev

如何在多显示器设置中映射外部触摸屏以忽略笔记本电脑?

来自分类Dev

CSS-模拟:在触摸屏设备上悬停效果

来自分类Dev

触摸屏滚动

来自分类Dev

禁用触摸屏

来自分类Dev

多个触摸屏

来自分类Dev

触摸屏滚动

来自分类Dev

在 Windows 7 中混合使用触摸屏和非触摸屏显示器?

来自分类Dev

多点触摸红外触摸屏如何工作

来自分类Dev

如何在Android上使用破碎的触摸屏授权和接受ADB RSA密钥

来自分类Dev

如何在Firefox Quantum中使触摸屏滚动工作?

Related 相关文章

热门标签

归档