(八)微信与H5的测试

webview   :   WEBVIEW_com.tencent.mm:tools


实例:

import time
from appium import webdriver


desired_caps = {}


desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1.2'
desired_caps['deviceName'] = 'MI 3'
desired_caps['appPackage'] = 'com.tencent.mm'
desired_caps['appActivity'] = 'com.tencent.mm.ui.LauncherUI'
desired_caps['chromeOptions']={'androidProcess': 'com.tencent.mm:tools'}


driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
time.sleep(10)
try:
	driver.find_element_by_xpath("//android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]").click()
	time.sleep(2)
	driver.find_element_by_xpath("//android.widget.ListView[@resource-id=\"com.tencent.mm:id/bld\"]/android.widget.LinearLayout[1]").click()
	# print driver.contexts
	time.sleep(5)
	driver.find_element_by_xpath("//android.widget.ListView[@resource-id=\"com.tencent.mm:id/a2i\"]/android.widget.RelativeLayout[2]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[2]/android.widget.FrameLayout[1]").click()
	time.sleep(10)
	driver.switch_to.context(u'WEBVIEW_com.tencent.mm:tools')
	print driver.current_context
	time.sleep(2)
	driver.find_element_by_xpath("//*[@id=\"vue\"]/div[1]/div[1]/div/div/div/div[2]/a[2]").click()
	print "huk"
	time.sleep(10)
	# print driver.getContextHandles()
	# driver.find_element_by_xpath("//android.widget.LinearLayout/android.widget.RelativeLayout[2]").click()
	# time.sleep(3)
	# driver.find_element_by_id("com.tencent.mm:id/i0").click()
except Exception, e:
	driver.quit()
driver.quit()


题外话:

一般webview的元素获取版本都是debug版本,这样浏览器才能识别

需要浏览器能够翻墙,不然就是一个空白

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值