ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

【python+appium自动化测试】--uiautomator高级用法:滚动查找页面

2021-03-08 17:05:41  阅读:242  来源: 互联网

标签:appium uiautomator python self UiSelector driver new android


互联网app测试经常遇到的问题:当前页面无法查找到某个元素,需要通过下拉操作到下一页或后续页面才能找到想要的内容

应用场景有:微信朋友圈查找某人发的几天前的朋友圈、微博等

 

可以使用如下方法:
举个例子,雪球app进入我的---下拉页面查找设置并点击
1  self.driver.find_element_by_android_uiautomator('new UiScrollable(new UiSelector().'
2                                                         'scrollable(true).instance(0)).'
3                                                         'scrollIntoView(new UiSelector().text("设置").'
4                                                         'instance(0));').click()

 

 1 # -*- coding:utf-8 -*-
 2 # author:xjw
 3 # date=2021/3/4
 4 
 5 from appium import webdriver
 6 from appium.webdriver.common.touch_action import TouchAction
 7 
 8 
 9 class Testappium:
10     def setup(self):
11         desired = {
12             "platformName": "Android",
13             "platformVersion": "6.0.1",
14             "deviceName": "127.0.0.1:7555",
15             "appPackage": "com.xueqiu.android",
16             "appActivity": ".view.WelcomeActivityAlias"
17         }
18 
19         self.driver = webdriver.Remote(command_executor="http://127.0.0.1:4723/wd/hub",desired_capabilities=desired)
20         self.driver.implicitly_wait(6)
21     # def teardown(self):
22     #     self.driver.quit
23 
24 #触屏操作滑动
25     def test_touchaction(self):
26         action=TouchAction(self.driver)
27         window_rect=self.driver.get_window_rect()
28         width=window_rect['width']
29         height=window_rect['height']
30         x1=int(width/2)
31         y_start=int(height*1/5)
32         y_end=int(height*4/5)
33 
34         action.press(x=x1,y=y_start).wait(200).move_to(x=x1,y=y_end).release().perform()
35     def test_uiautomator(self):
36         self.driver.find_element_by_android_uiautomator('new UiSelector().text("我的")').click()
37         self.driver.find_element_by_android_uiautomator('new UiSelector().textContains("帐号密码登录")').click()
38         self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.xueqiu.android:id/login_account")').send_keys('1234')
39         self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.xueqiu.android:id/login_password")').send_keys('abcd')
40         self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.xueqiu.android:id/button_next")').click()
41     def test_scrolldown(self):
42         self.driver.find_element_by_android_uiautomator('new UiSelector().text("我的")').click()
43         self.driver.find_element_by_android_uiautomator('new UiScrollable(new UiSelector().'
44                                                         'scrollable(true).instance(0)).'
45                                                         'scrollIntoView(new UiSelector().text("设置").'
46                                                         'instance(0));').click()

 

标签:appium,uiautomator,python,self,UiSelector,driver,new,android
来源: https://www.cnblogs.com/xiangjingwei/p/14500658.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有