android – 使用webdriver python的触摸事件示例?

android – 使用webdriver python的触摸事件示例?,第1张

概述我在网上看到了大约100个 touch event examples for the Java webdriver,但是没有一个用于python. 有人会非常友好地在这里张贴一个,这样可以节省人们数小时的搜索时间吗? 这是我尝试在Android模拟器中的元素上执行基本的double_tap以放大它.非常感谢 编辑:感谢朱利安的帮助,我能够找出缺失的链接:由于某种原因,触摸 *** 作最后需要一个额外的.p 我在网上看到了大约100个 touch event examples for the Java webdriver,但是没有一个用于python.
有人会非常友好地在这里张贴一个,这样可以节省人们数小时的搜索时间吗?
这是我尝试在AndroID模拟器中的元素上执行基本的double_tap以放大它.非常感谢

编辑:感谢朱利安的帮助,我能够找出缺失的链接:由于某种原因,触摸 *** 作最后需要一个额外的.perform().您将在下面找到一系列触摸事件 – 代码更清晰.请享用!

import unittest,timefrom selenium import webdriverprint "Here are our available touch actions (ignore the ones that look like __xx__): ",dir(webdriver.touchActions)#print dir(webdriver)class Test(unittest.TestCase):    def setUp(self):        self.driver = webdriver.Remote(command_executor='http://localhost:8080/wd/hub',desired_capabilitIEs=webdriver.DesiredCapabilitIEs.ANDROID)        self.touch =webdriver.touchActions(self.driver)        #self.driver = touchActions(self.driver)        #self.driver = webdriver.firefox()        self.driver.implicitly_wait(30)    def testHotmail(self):        self.driver.get("http://www.hotmail.com")        elem=self.driver.find_element_by_CSS_selector("input[name='login']")        #tap command        self.touch.tap(elem).perform()        time.sleep(2)        elem.send_keys("hello world")        time.sleep(2)        #double tap        self.touch.double_tap(elem).perform()        time.sleep(2)        #testing that regular webdriver commands still work        print self.driver.find_element_by_partial_link_text("Can't access").text        elem= self.driver.find_element_by_CSS_selector("input[type='submit']")        self.touch.tap(elem).perform()        time.sleep(3)    def tearDown(self):        time.sleep(3)        try:            self.driver.quit()        except Exception:            print(" TearDown Method: browser seems already closed.")        passif __name__ == "__main__":    unittest.main()

这是一个原始的Java示例

WebElement toFlick = driver.findElement(By.ID("image"));// 400 pixels left at normal speedAction flick = getBuilder(driver).flick(toFlick,-400,FlickAction.SPEED_norMAL)        .build();flick.perform();WebElement secondImage = driver.findElement(“secondImage”);assertTrue(secondImage.isdisplayed());
解决方法 我已经对你的例子进行了一些调整,至少测试运行没有错误.当用户双击用户名字段时,我不知道您希望该网站做什么…

这是修改后的代码:

import unittest,timefrom selenium.webdriver import Remotefrom selenium.webdriver import  DesiredCapabilitIEsfrom selenium.webdriver.remote import webelement,commandfrom selenium.webdriver.common.action_chains import ActionChainsfrom selenium.webdriver.common.touch_actions import touchActionsclass Test(unittest.TestCase):    def setUp(self):        remote = Remote(command_executor='http://localhost:8080/wd/hub',desired_capabilitIEs=DesiredCapabilitIEs.ANDROID)        self.remote=remote        remote.implicitly_wait(30)    def tearDown(self):        pass    def testname(self):        # self.remote.get("http://icd.intraxinc.com/pxr")        self.remote.get("https://icd.intraxinc.com/pxr/ext/login.action")        elems= self.remote.find_element_by_CSS_selector("#j_username")        print dir(self)        print dir(self.remote)        touchactions = touchActions(self.remote)        print dir(touchactions)        touchactions.double_tap(elems)if __name__ == "__main__":    #import sys;sys.argv = ['','Test.testname']    unittest.main()

我在示例中留下了各种调试打印语句,以向您展示我是如何调查您所面临的问题的.我还将URL更改为您的登录页面重定向到的URL.这是我在设备上安装的AndroID驱动程序版本所遇到的无关问题的解决方法.

仅供参考:我在运行AndroID 4.0.4的AndroID手机上测试了androID-server-2.21.0.apk.以下是示例代码的重大更改

touchactions = touchActions(self.remote)        print dir(touchactions)        touchactions.double_tap(elems)
总结

以上是内存溢出为你收集整理的android – 使用webdriver python的触摸事件示例?全部内容,希望文章能够帮你解决android – 使用webdriver python的触摸事件示例?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1129218.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存