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版本,這樣瀏覽器才能識別
需要瀏覽器能夠翻牆,不然就是一個空白