【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. 下面主要是针对自 ...
随机推荐
- PAT 甲级 1051 Pop Sequence (25 分)(模拟栈,较简单)
1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the ord ...
- (九)UML之活动图
一.概念 二. 在Rational rose 中画活动图 2.1 创建Activity Diagram 2.2 画图
- sqlserver 数据库操作导出数据sql工具
软件名称sqldbx 下载URL https://download.csdn.net/download/yanghl1998/7832861 Navicat Premium 这个工具任何类型数据库 ...
- python的注释规范
pydoc是python自带的一个文档生成工具,使用pydoc可以很方便的查看类和方法结构 本文主要介绍:1.查看文档的方法.2.html文档说明.3.注释方法. 一.查看文档的方法 方法1: ...
- Tensorflow 2.0 datasets数据加载
导入包 import tensorflow as tf from tensorflow import keras 加载数据 tensorflow可以调用keras自带的datasets,很方便,就是有 ...
- php 的 socket简单原理及实现
什么是socket socket:网络上的两个程序通过一个双向的通信连接实现数据的交换,连接的一端称为一个socket. 因此socket运行是置少有2个端组成,一个为服务端一个为客户端(客户端可以多 ...
- linux系统中RAID5磁盘冗余阵列配置(5块磁盘)
RAID5:需要至少三块(含)硬盘,兼顾存储性能.数据安全和储存成本. 如图所示”parity”块中保存的是其他硬盘数据的奇偶校验信息(并非其他硬盘的数据),以数据的奇偶校验信息来保证数据的安全,RA ...
- order pick-up and delivery problem
问题一: pi表示取第i个单,di表示送第i个单.di不能在pi的前面.给一个取单送单的顺序,问是否是valid顺序. public boolean isValidOrderList(List< ...
- [转帖]持久化journalctl日志清空命令查看配置参数详解
持久化journalctl日志清空命令查看配置参数详解 最近 linux上面部署服务 习惯使用systemd 进行处理 这样最大的好处能够 使用journalctl 进行查看日志信息. 今天清理了下 ...
- Redis 5.0.5 Install manual
Redis 5.0.5 安装文档(Install manual) 一.单实例安装 标题 内容 测试环境 Centos 7 虚拟机 vbox redis版本 redis 5.0.5 1.编译安装redi ...