加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
appium_test_backup.py 9.19 KB
一键复制 编辑 原始数据 按行查看 历史
叶子 提交于 2019-10-21 21:08 . first
#coding=utf-8
import time
from appium import webdriver
def record_user_msg_and_save(driver, is_multil_protect=False):
fout = open('user_info.csv', 'a')
# 是否为多保单 is_multil_protect
# 客户名字
try:
user_name = driver.find_element_by_xpath(
'//android.view.ViewGroup/android.view.ViewGroup[2]/android.widget.ScrollView[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.widget.TextView[2]').text.encode('utf8')
if len(user_name) < 2:
a = 1 / 0
fout.write(user_name)
except:
print('time out')
fout.close()
time.sleep(1)
try:
driver.find_element_by_xpath(
'//android.view.ViewGroup/android.view.ViewGroup[1]/android.view.ViewGroup[2]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.widget.TextView[2]').text.encode(
'utf8')
is_multil_protect = True
driver.swipe(700, 1190, 700, 1070, duration=5000)
except:
print('not info page')
record_user_msg_and_save(driver, is_multil_protect=is_multil_protect)
return
fout.write('\t')
# 什么银行
try:
fout.write(driver.find_element_by_xpath('//android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup[2]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.widget.TextView[2]').text.encode('utf8'))
except:
pass
fout.write('\t')
# 购买银行尾号
try:
fout.write(driver.find_element_by_xpath('//android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup[2]/android.view.ViewGroup[2]/android.view.ViewGroup[1]/android.widget.TextView[2]').text.encode('utf8'))
except:
pass
fout.write('\t')
if is_multil_protect:
driver.swipe(700, 500, 700, 800, duration=1000)
# 保单号 没为题
try:
fout.write(driver.find_element_by_xpath('//android.view.ViewGroup/android.view.ViewGroup[1]/android.view.ViewGroup[2]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.widget.TextView[2]').text.encode('utf8'))
except:
pass
fout.write('\t')
# 生效日期 没为题
try:
if is_multil_protect:
fout.write(driver.find_element_by_xpath(
'//android.view.ViewGroup/android.view.ViewGroup[1]/android.view.ViewGroup[2]/android.view.ViewGroup[3]/android.view.ViewGroup[1]/android.widget.TextView[2]').text.encode(
'utf8'))
else:
fout.write(driver.find_element_by_xpath('//android.view.ViewGroup/android.view.ViewGroup[1]/android.view.ViewGroup[2]/android.view.ViewGroup[2]/android.view.ViewGroup[1]/android.widget.TextView[2]').text.encode('utf8'))
except:
pass
fout.write('\t')
if is_multil_protect:
driver.swipe(700, 1190, 700, 1070, duration=5000)
# 翻页
driver.swipe(700, 1190, 700, 168, duration=5000)
# 性别
try:
fout.write(driver.find_element_by_xpath('//android.widget.ScrollView/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.widget.ScrollView[1]/android.view.ViewGroup[1]/android.view.ViewGroup[2]/android.view.ViewGroup[1]/android.widget.TextView[2]').text.encode('utf8'))
except:
pass
fout.write('\t')
# 出生日期
try:
fout.write(driver.find_element_by_xpath('//android.view.ViewGroup/android.view.ViewGroup[3]/android.view.ViewGroup[1]/android.widget.TextView[2]').text.encode('utf8'))
except:
pass
fout.write('\t')
# 手机电话
try:
fout.write(driver.find_element_by_xpath('//android.view.ViewGroup/android.view.ViewGroup[7]/android.view.ViewGroup[1]/android.widget.TextView[2]').text.encode('utf8'))
except:
pass
fout.write('\t')
# 电话号码
try:
fout.write(driver.find_element_by_xpath('//android.view.ViewGroup/android.view.ViewGroup[8]/android.view.ViewGroup[1]/android.widget.TextView[2]').text.encode('utf8'))
except:
pass
fout.write('\t')
# 地址
try:
fout.write(driver.find_element_by_xpath('//android.view.ViewGroup/android.view.ViewGroup[9]/android.view.ViewGroup[1]/android.widget.TextView[2]').text.encode('utf8'))
except:
pass
fout.write('\t')
# 翻页
driver.swipe(700, 1190, 700, 168, duration=5000)
driver.swipe(700, 1190, 700, 168, duration=5000)
# 受益人
try:
fout.write(driver.find_element_by_xpath('//android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup[2]/android.widget.ScrollView[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.widget.TextView[1]').text.encode('utf8'))
except:
pass
fout.write('\t')
# 保险名称
try:
fout.write(driver.find_element_by_xpath('//android.widget.ScrollView/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.widget.TextView[2]').text.encode('utf8'))
except:
pass
fout.write('\t')
# 保多少年
try:
fout.write(driver.find_element_by_xpath('//android.view.ViewGroup/android.view.ViewGroup[1]/android.view.ViewGroup[2]/android.view.ViewGroup[1]/android.widget.TextView[3]').text.encode('utf8'))
except:
pass
fout.write('\t')
# 交多少年
try:
fout.write(driver.find_element_by_xpath('//android.view.ViewGroup/android.view.ViewGroup[1]/android.view.ViewGroup[2]/android.view.ViewGroup[1]/android.widget.TextView[5]').text.encode('utf8'))
except:
pass
fout.write('\t')
# 将投保险种收起来
# driver.find_element_by_xpath('//android.view.ViewGroup/android.view.ViewGroup[3]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.widget.ImageView[1]').click()
# 翻页
driver.swipe(700, 1190, 700, 112, duration=1000)
# 翻页
driver.swipe(700, 1190, 700, 112, duration=1000)
# 交多少钱
try:
fout.write(driver.find_element_by_xpath(
'//android.view.ViewGroup/android.view.ViewGroup[3]/android.view.ViewGroup[2]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.widget.TextView[2]').text.encode(
'utf8'))
except:
try:
fout.write(driver.find_element_by_xpath(
'//android.view.ViewGroup/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.widget.TextView[2]').text.encode(
'utf8'))
except:
pass
fout.write('\t')
fout.write('\n')
fout.close()
# 返回
driver.find_element_by_xpath('//android.widget.FrameLayout/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]').click()
time.sleep(1)
def get_one_page_element_and_open_one_info_record_msg(driver):
one_page_elements = driver.find_elements_by_xpath(
'//android.widget.ScrollView/android.view.ViewGroup[1]/android.view.ViewGroup')
for one_element in one_page_elements:
one_element.click()
time.sleep(3)
record_user_msg_and_save(driver)
try:
# 判断是否到底了
driver.find_element_by_xpath(
'//android.widget.ScrollView/android.view.ViewGroup[1]/android.widget.TextView[1]').text
print('over...')
except:
driver.scroll(one_page_elements[-1], one_page_elements[0], duration=5000)
get_one_page_element_and_open_one_info_record_msg(driver)
if __name__ == '__main__':
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '7.1.1'
desired_caps['deviceName'] = 'cc8fde10'
# 可以通过newcommandtimeout将超时时间改长,这样就解决了该问题!!
# 超时时间可按照实际情况自定义!
desired_caps['newCommandTimeout'] = '2000000'
# desired_caps['platformVersion'] = '5.1.1'
# desired_caps['deviceName'] = '2e4bd0dc'
# desired_caps['appPackage'] = 'com.android.calculator2'
# desired_caps['appActivity'] = '.Calculator'
desired_caps['appPackage'] = 'com.picc.etong'
desired_caps['appActivity'] = 'com.picc.nmmslogin.activity.GroupWelcomeActivity'
desired_caps['appActivity'] = 'com.picc.etongmodules.group.activity.GroupFramework.GroupMainActivity'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
raw_input()
get_one_page_element_and_open_one_info_record_msg(driver)
raw_input()
get_one_page_element_and_open_one_info_record_msg(driver)
raw_input()
get_one_page_element_and_open_one_info_record_msg(driver)
raw_input()
get_one_page_element_and_open_one_info_record_msg(driver)
raw_input()
get_one_page_element_and_open_one_info_record_msg(driver)
driver.quit()
raw_input()
# driver.find_element_by_name("1").click()
#
# driver.find_element_by_name("5").click()
#
# driver.find_element_by_name("9").click()
#
# driver.find_element_by_name("delete").click()
#
# driver.find_element_by_name("9").click()
#
# driver.find_element_by_name("5").click()
#
# driver.find_element_by_name("+").click()
#
# driver.find_element_by_name("6").click()
#
# driver.find_element_by_name("=").click()
# driver.quit()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化