【appium】appium中的元素定位和基本操作
# coding=utf-8 from appium import webdriver
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC class Base: def __init__(self):
self.driver = self.get_driver()
self.size = self.get_size() def get_driver(self):
capabilities = {
"platformName": "Android",
"automationName": "UiAutomator2", # 测试平台,默认为appium,为了get_tost此处为automator2
"deviceName": "127.0.0.1:21513",
"app": "E:\\pythonAppium\\autoTest\\apps\\mukewang.apk",
"appWaitActivity": "cn.com.open.mooc.user.register.MCPhoneRegisterAty",
"noReset": "True", # 是否重装
# "chromeOptions": {"androidProcess": "WEBVIEW_cn.com.open.mooc"} }
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", capabilities)
return driver def get_size(self):
# 获取屏幕大小
size = self.driver.get_window_size()
width = size['width']
height = size['height']
return width, height def swipe_right(self):
"""
从左向右滑
:return:
"""
x = self.get_size()[0]/10
x1 = self.get_size()[0]/10*9
y = self.get_size()[1]/2
self.driver.swipe(x, y, x1, y) def swipe_left(self):
"""
从右向左滑
:return:
"""
x = self.get_size()[0]/10*9
x1 = self.get_size()[0]/10
y = self.get_size()[1]/2
self.driver.swipe(x, y, x1, y) def swipe_up(self):
"""
从下往上滑
:return:
"""
x = self.get_size()[0]/2
y = self.get_size()[1]/10*9
y1 = self.get_size()[1]/10
self.driver.swipe(x, y, x, y1) def swipe_down(self):
"""
从上往下滑
:return:
"""
x = self.get_size()[0]/2
y = self.get_size()[1]/10
y1 = self.get_size()[1]/10*9
self.driver.swipe(x, y, x, y1) def swipe_on(self, direction):
if direction == 'left':
self.swipe_left()
elif direction == 'right':
self.swipe_right()
elif direction == 'up':
self.swipe_up()
else:
self.swipe_down() def go_to_login(self):
"""
跳转到登录界面
:return:
"""
self.driver.find_element_by_id('cn.com.open.mooc:id/tv_go_login').click() def login_by_id(self):
self.driver.find_element_by_id('cn.com.open.mooc:id/account_edit').send_keys('')
# self.drvier.find_element_by_id('cn.com.open.mooc:id/password_edit').send_keys('dianzi1312')
self.driver.find_element_by_id('cn.com.open.mooc:id/login').click() def login_by_uiautomator(self):
self.driver.find_element_by_android_uiautomator('new UiSelector().text("13055211990")').clear()
self.driver.find_element_by_android_uiautomator('new UiSelector().text("手机号/邮箱")').sendkeys('')
self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("cn.com.open.mooc:id/password_edit")').sendkeys('dianzi1312') def login_by_xpath(self):
# 在所有层级查找text包含忘记的元素
# self.drvier.find_element_by_xpath('//*[cotains(@text,"忘记")]').click()
# 在class为..中查找text为忘记的元素
# self.drvier.find_element_by_xpath('//android.widget.TextView[@text="忘记"]').click()
# /../preceding-sibiling::寻找上级节点
self.driver.find_element_by_xpath('//android.widget.TextView@resource-id="cn.com.open.mooc:id/login_lable"]/../preceding-sibiling::*[@index="1]') def get_webview(self):
time.sleep(20)
webviews = self.driver.contexts
print(webviews)
for view in webviews:
if 'WEBVIEW_cn.com.open.mooc' in view:
print("")
self.driver.switch_to.context(view)
print("")
break
self.driver.find_element_by_link_text('JAVA').click() def get_tost(self):
time.sleep(2)
tost_locator = ("xpath", "//*[contains(@text,'请输入密码')]")
result = WebDriverWait(self.driver, 10, 0.1).until(EC.presence_of_element_located(tost_locator))
print(result) if __name__ == '__main__':
run = Base()
time.sleep(5)
# run.login_by_uiautomator()
run.go_to_login()
time.sleep(2)
run.login_by_id()
run.get_tost()
【appium】appium中的元素定位和基本操作的更多相关文章
- appium自动化测试之UIautomatorviewer元素定位
appium自动化测试之UIautomatorviewer元素定位 标签(空格分隔): uiautomatorviewer元素定位 前面的章节,已经总结了怎么搭建环境,怎样成功启动一个APP了,这里具 ...
- 『与善仁』Appium基础 — 17、元素定位工具(一)
目录 1.uiautomatorviewer介绍 2.uiautomatorviewer工具打开方式 3.uiautomatorviewer布局介绍 4.uiautomatorviewer工具的使用 ...
- 『与善仁』Appium基础 — 18、元素定位工具(二)
目录 1.Appium Inspector介绍 2.Appium Inspector打开方式 3.Appium Inspector布局介绍 4.Appium Inspector工具的配置 5.Appi ...
- 『与善仁』Appium基础 — 19、元素定位工具(三)
目录 1.Chrome Inspect介绍 2.Chrome Inspect打开方式 3.Chrome Inspect工具的使用 (1)Chrome Inspect工作前提 (2)Chrome Ins ...
- 5、通过Appium Desktop实现页面元素定位
之前我们已经安装了Appium Desktop,下面就让我们使用Appium Desktop实现页面元素定位 1.首先我们打开Appium Desktop,进入如下界面,点击Start Server ...
- Appium Python 五:元素定位
总结 单个元素定位: driver.find_element_by_accessibility_id(id) driver.find_element_by_android_uiautomator(ui ...
- python+Appium自动化:H5元素定位
问题思考 在混合开发的App中,经常会有内嵌的H5页面.那么这些H5页面元素该如何进行定位操作呢? 解决思路 针对这种场景直接使用前面所讲的方法来进行定位是行不通的,因为前面的都是基于Andriod原 ...
- python+Appium自动化:id元素定位
元素定位 与web自动化一样,app自动化元素定位也是非常重要的一环,,appium也是提供了很多元素定位的方法,比如:id.name.class.层级定位等等. 元素定位方式 id name cla ...
- Appium学习笔记4_元素定位方法
Appium之元素定位,如果对Android上如何使用工具获取页面元素有问题的,请转战到这:http://www.cnblogs.com/taoSir/p/4816382.html. 下面主要是针对自 ...
随机推荐
- pycharm调用shell命令
在pycharm中调用shell命令 1.调用普通命令 # -*- coding:UTF-8 -*- import subprocess subprocess.call(["ls /home ...
- Win10安装PostgreSQL9.6
首先去 官网 下载PostgreSQL 9.6. 可以看到最新版已经到11了,但是我们这里还是以9.6.10版本为例进行下载. 下载好之后点击进行安装,安装期间的一些参数如下: 默认的安装位置是C:\ ...
- maven仓库里如何搜索三方包?查看流行软件
问题 这个仓库提供了搜索,但是功能比较弱,不支持groupid/artfactid的联合搜索 https://mvnrepository.com/ 解决 直接在搜索的url里添加groupid和art ...
- Python 动态规划算法
背包问题 假设你是一个小偷,背一个可装4磅东西的背包.可盗窃的商品有如下3件: 音响,4磅,价值3000美元 笔记本电脑,3磅,价值2000美元 吉他,1磅,价值1500美元 为了让盗窃的商品价值最高 ...
- sklearn.svc 参数
sklearn.svc 参数 sklearn中的SVC函数是基于libsvm实现的,所以在参数设置上有很多相似的地方.(PS: libsvm中的二次规划问题的解决算法是SMO). 对于SVC函数的参数 ...
- 阿里云ECS服务器活动99元一年(2019年 Hi拼团,拼着买,更划算)
2019年10月22日更新,阿里云推荐有礼活动:ECS突发性能T6-低至99元/年赶紧上车~ 低价高性能,拼着买更划算 点我参加活动>> 购买前领取阿里云幸运券,更有可能享受折上折的优惠. ...
- Java 23中设计模式
创建型模式(5): --单例模式.工厂模式.抽象工厂模式.建造者模式.原型模式. 结构型模式(7): --适配器模式.桥接模式.装饰模式.组合模式.外观模式.享元模式.代理模式. 行为模式(11): ...
- Ant 构建 Jmeter脚本报错详解
在搭建Ant构建Jmeter脚本的时候,小组成员遇到了各种问题. 再这里总结一下,遇到类似问题的可以做个参考 1.提示 does not exist 解决方案: 出现这种的问题原因有很多. 先排除权限 ...
- EventBus使用的坑
最近使用eventbus发送通知,在想该怎么携带List集合数据.于是尝试直接发送List. 使用一次,正常接收.使用两次,出现类转换异常.原来在接收List类型的消息时,并不会管List内的泛型,是 ...
- Jmeter逻辑控制器: If控制器的解读
Jmeter官网其实有很详细的文档,点此跳转到官网,下面我来解读一下官网的文档,如有错误,欢迎指出. 一.官网解读 Name 在结果树中显示的名字. Comments 备注.相当于代码中的注释. Ex ...