【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. 下面主要是针对自 ...
随机推荐
- Ubuntu 14.04 apache安装配置
http://jingyan.baidu.com/article/6d704a130c8a0d28da51ca5f.html Ubuntu 14.04 apache安装配置 1.安装 ~# apt-g ...
- Node.js ORM框架Sequelize使用示例
示例代码: const Sequelize = require('sequelize'); const sequelize = new Sequelize('database', 'username' ...
- react ant design TreeNode——树形菜单笔记
2017-12-04补充说明——树形菜单版本号2.x 设置默认该树形组件展开(默认展开所有树节点) 参考文档的写法: defaultExpandAll={true} //经过测试并不生效, 另外注意 ...
- Spring-boot内置的程序管理监控工具-Actuator
1.引入jar包: <dependencies> <dependency> <groupId>org.springframework.boot</groupI ...
- esigner中name和comment互換
1 PowerDesigner中批量根据对象的name生成comment的脚本 执行方法:Open PDM -- Tools -- Execute Commands -- Run Script Opt ...
- nginx 工作原理总结
1. Nginx的模块与工作原理 Nginx由内核和模块组成,其中,内核的设计非常微小和简洁,完成的工作也非常简单,仅仅通过查找配置文件将客户端请求映射到一个location block(locat ...
- Mysql: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
2019-05-28 01:53:42.762 [message remind thread-24] ERROR druid.sql.Statement - {conn-10327, stmt-320 ...
- Win10 自定义鼠标右键菜单
1. 点击文件鼠标右键显示软件 1.1 步骤 win+R输入regedit进入注册表 定位到HKEY_CLASSES_ROOT\*\shell下 在shell创建一个你想要的右键文件 例如:Kinok ...
- WUSTOJ 1232: 矩阵乘法(C)
1232: 矩阵乘法 Time Limit: 1 Sec Memory Limit: 128 MB 64bit IO Format: %lld Description 小明明正在学习线性代数,老师布置 ...
- python实现数字0开始的索引,对应Execl的字母方法
字母转数字方法: import re col = row = [] # 输入正确格式的定位,A2,AA2有效,AAB2无效 while len(col) == 0 or len(row) == 0 o ...