加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
appium_test.py 13.94 KB
一键复制 编辑 原始数据 按行查看 历史
叶子 提交于 2019-10-21 21:08 . first
#coding:utf-8
import time
from appium import webdriver
baodan_list = []
def record_user_msg_and_save(driver, is_multil_protect=False):
fout = open('user_info.csv', 'a')
# 是否为多保单 is_multil_protect
# 客户名字 driver.find_element_by_xpath("//android.widget.TextView[@text='姓名']/parent::android.view.ViewGroup/android.widget.TextView[2]")
bao_dan_hao = ''
try:
user_name = driver.find_element_by_xpath("//android.widget.TextView[@text='姓名']/parent::android.view.ViewGroup/android.widget.TextView[2]").text.encode('utf8')
if len(user_name) < 2:
a = 1 / 0
bao_dan_hao = driver.find_element_by_xpath(
"//android.widget.TextView[@text='保单号']/parent::android.view.ViewGroup/android.widget.TextView[2]").text.encode(
'utf8')
if bao_dan_hao in baodan_list:
# 返回
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)
return
baodan_list.append(bao_dan_hao)
fout.write(user_name)
except:
try:
driver.swipe(700, 1190, 700, 168, duration=5000)
user_name = driver.find_element_by_xpath(
"//android.widget.TextView[@text='姓名']/parent::android.view.ViewGroup/android.widget.TextView[2]").text.encode(
'utf8')
fout.write(user_name)
except:
print('time out')
fout.close()
record_user_msg_and_save(driver, is_multil_protect=is_multil_protect)
return
fout.write('\t')
driver.swipe(700, 168, 700, 1190, duration=1000)
# 什么银行
while True:
try:
fout.write(driver.find_element_by_xpath(
"//android.widget.TextView[@text='支付银行']/parent::android.view.ViewGroup/android.widget.TextView[2]").text.encode(
'utf8'))
break
except:
driver.swipe(700, 1190, 700, 168, duration=5000)
fout.write('\t')
# 购买银行尾号
try:
fout.write(driver.find_element_by_xpath("//android.widget.TextView[@text='银行账号']/parent::android.view.ViewGroup/android.widget.TextView[2]").text.encode('utf8'))
except:
pass
fout.write('\t')
if is_multil_protect:
driver.swipe(700, 500, 700, 800, duration=1000)
driver.swipe(700, 168, 700, 1190, duration=1000)
# 保单号 没为题
try:
fout.write(bao_dan_hao)
except:
pass
fout.write('\t')
# 生效日期 没为题
try:
if is_multil_protect:
fout.write(driver.find_element_by_xpath("//android.widget.TextView[@text='生效日期']/parent::android.view.ViewGroup/android.widget.TextView[2]").text.encode(
'utf8'))
else:
fout.write(driver.find_element_by_xpath("//android.widget.TextView[@text='生效日期']/parent::android.view.ViewGroup/android.widget.TextView[2]").text.encode('utf8'))
except:
pass
fout.write('\t')
# 保单状态
fout.write(driver.find_element_by_xpath(
"//android.widget.TextView[@text='保单状态']/parent::android.view.ViewGroup/android.widget.TextView[2]").text.encode(
'utf8'))
fout.write('\t')
if is_multil_protect:
driver.swipe(700, 1190, 700, 1070, duration=5000)
# 翻页
driver.swipe(700, 1190, 700, 168, duration=5000)
# 性别
while True:
try:
fout.write(driver.find_element_by_xpath("//android.widget.TextView[@text='性别']/parent::android.view.ViewGroup/android.widget.TextView[2]").text.encode('utf8'))
break
except:
driver.swipe(700, 1190, 700, 168, duration=5000)
fout.write('\t')
# 出生日期
while True:
try:
fout.write(driver.find_element_by_xpath("//android.widget.TextView[@text='生日']/parent::android.view.ViewGroup/android.widget.TextView[2]").text.encode('utf8'))
break
except:
driver.swipe(700, 1190, 700, 168, duration=5000)
fout.write('\t')
# 手机电话
while True:
try:
fout.write(driver.find_element_by_xpath("//android.widget.TextView[@text='手机电话']/parent::android.view.ViewGroup/android.widget.TextView[2]").text.encode('utf8'))
break
except:
driver.swipe(700, 1190, 700, 168, duration=5000)
fout.write('\t')
# 电话号码
while True:
try:
fout.write(driver.find_element_by_xpath("//android.widget.TextView[@text='电话号码']/parent::android.view.ViewGroup/android.widget.TextView[2]").text.encode('utf8'))
break
except:
driver.swipe(700, 1190, 700, 168, duration=5000)
fout.write('\t')
# 地址
while True:
try:
fout.write(driver.find_element_by_xpath("//android.widget.TextView[@text='联系地址']/parent::android.view.ViewGroup/android.widget.TextView[2]").text.encode('utf8'))
break
except:
driver.swipe(700, 1190, 700, 168, duration=5000)
fout.write('\t')
# 翻页
driver.swipe(700, 1190, 700, 168, duration=5000)
driver.swipe(700, 1190, 700, 168, duration=5000)
# 受益人
while True:
try:
driver.find_element_by_xpath("//android.widget.TextView[@text='被保险人身事故时生存的配偶、父母、子女']").text.encode('utf8')
fout.write('法定')
break
except:
try:
driver.find_element_by_xpath("//android.widget.TextView[@text='受益人']")
fout.write('指定')
break
except:
driver.swipe(700, 1190, 700, 168, duration=5000)
fout.write('\t')
# 保险名称
while True:
try:
fout.write(driver.find_element_by_xpath("//android.widget.TextView[@text='主']/parent::android.view.ViewGroup/android.widget.TextView[2]").text.encode('utf8'))
break
except:
driver.swipe(700, 1190, 700, 168, duration=5000)
fout.write('\t')
# 保多少年
while True:
try:
fout.write(driver.find_element_by_xpath("//android.widget.TextView[@text='保险期间:']/parent::android.view.ViewGroup/android.widget.TextView[3]").text.encode('utf8'))
break
except:
driver.swipe(700, 1190, 700, 168, duration=5000)
fout.write('\t')
# 交多少年
try:
fout.write(driver.find_element_by_xpath("//android.widget.TextView[@text='保险期间:']/parent::android.view.ViewGroup/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.widget.TextView[@text='首期/趸交保险费合计']/parent::android.view.ViewGroup/android.widget.TextView[2]").text.encode(
'utf8'))
except:
pass
# 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):
global baodan_list
one_page_elements = None
try:
one_page_elements = driver.find_elements_by_xpath(
'//android.widget.ScrollView/android.view.ViewGroup[1]/android.view.ViewGroup')
except:
time.sleep(1)
get_one_page_element_and_open_one_info_record_msg(driver)
return
for one_element in one_page_elements:
try:
baoxianming = one_element.find_elements_by_xpath("//android.widget.TextView")[3].text.encode('utf-8')
print(baoxianming)
if '金鼎富贵两全保险' in baoxianming and '分红型' in baoxianming and 'C款' in baoxianming:
continue
except:
print('print baoxian ming error')
try:
driver.scroll(one_page_elements[-1], one_page_elements[0], duration=5000)
except:
pass
get_one_page_element_and_open_one_info_record_msg(driver)
return
try:
one_element.find_element_by_xpath("//android.widget.TextView[@text='金鼎富贵两全保险(分红型)(C款)']")
one_element = None
continue
except:
pass
try:
one_element.click()
one_element = None
time.sleep(3)
except:
try:
driver.scroll(one_page_elements[-1], one_page_elements[0], duration=5000)
except:
pass
get_one_page_element_and_open_one_info_record_msg(driver)
return
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...')
import winsound
duration = 2000 # millisecond
freq = 440 # Hz
winsound.Beep(freq, duration)
winsound.Beep(freq, duration)
winsound.Beep(freq, duration)
baodan_list = []
except:
try:
driver.scroll(one_page_elements[-1], one_page_elements[0], duration=5000)
except:
pass
time.sleep(3)
get_one_page_element_and_open_one_info_record_msg(driver)
if __name__ == '__main__':
# 设置编码utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
# 显示当前默认编码方式
print sys.getdefaultencoding()
desired_caps = {}
desired_caps['noReset'] = 'True' #启动app时不要清除app里的原有的数据
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '7.1.1'
desired_caps['platformVersion'] = '7.1.1'
desired_caps['deviceName'] = '127.0.0.1:62001' # 夜神
desired_caps['deviceName'] = 'cc8fde10' # 360
# 可以通过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()
while True:
try:
driver.swipe(700, 1190, 700, 112, duration=3000)
# 判断是否到底了
down_txt = driver.find_element_by_xpath(
'//android.widget.ScrollView/android.view.ViewGroup[1]/android.widget.TextView[1]').text.encode('utf-8')
if '已加载全部' in down_txt:
print('over...')
break
except:
pass
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)
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)
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)
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)
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 助手
尝试更多
代码解读
代码找茬
代码优化