【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. 下面主要是针对自 ...
随机推荐
- Python基础之set集合与函数
set集合 集合是一个无序且不重复的元素组合,以大括号表示.使用详情: >>> b=set(a) >>> type(b) <class 'set'> & ...
- (一)深入java虚拟机之内存溢出与分析
一.内存溢出程序 public class Test { public static void main(String[] args) { List<User> userList=new ...
- Win10使用mysqldump导出csv文件及期间遇到的问题
作为测试,我们这里使用了名为testdb的数据库中的名为test_table的表,首先我们使用如下SQL来查看其中有何数据: select * from testdb.test_table 数据如下: ...
- iOS-UITextField的使用
UITextField UITextField * accountField = [[UITextField alloc] initWithFrame:CGRectMake(85.0f, 60.0f ...
- Vidual Studio vs2013彻底卸载
我的win10 1803 2019年年中升级的,非常后悔,持续不间断的假死状态让人很无奈.又不舍得回退,因为很多保存的隐藏数据. 开始清理系统吧,东西越少性能越好,于是电脑就成了纯净版,甚至连 看到了 ...
- Charles 教程
本文介绍 charles 教程 - 代理抓包的使用方法 本文参考了:阿西河 Charles 教程 Charles Charles是一个HTTP代理/ HTTP监视器/反向代理,使开发人员能够查看其机器 ...
- csu 1756: Prime
1756: Prime Submit Page Summary Time Limit: 3 Sec Memory Limit: 128 Mb Submitted: 281 ...
- 论文阅读 | Transformer-XL: Attentive Language Models beyond a Fixed-Length Context
0 简述 Transformer最大的问题:在语言建模时的设置受到固定长度上下文的限制. 本文提出的Transformer-XL,使学习不再仅仅依赖于定长,且不破坏时间的相关性. Transforme ...
- hadoop WordCount例子详解。
[学习笔记] 下载hadoop-2.7.4-src.tar.gz,拷贝hadoop-2.7.4-src.tar.gz中hadoop-mapreduce-project\hadoop-mapreduce ...
- (九)Javabean与Jsp(来自那些年的笔记)
目录 JavaBean 在JSP中使用JavaBean 标签用法 带标签体的 JavaBean 标签 setProperty 标签 getProperty 标签 JSP开发模式 案列:使用 模式一 编 ...