在 log 中一直只显示只有 NATIVE_APP,看了很多朋友的帖子,尝试了好多方法还是不可以
from appium import webdriver
from appium.webdriver.mobilecommand import MobileCommand
import time
desired_caps = {'platformName': 'Android',
'platformVersion': '5.1',
'deviceName': 'MEIZU PRO5',
'appPackage': 'com.tencent.mm',
'appActivity':'com.tencent.mm.ui.LauncherUI',
'unicodeKeyboard': True,
'resetKeyboard': True,
'chromeOptions': {'androidProcess': 'com.android.browser'}
}
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.find_element_by_id("com.tencent.mm:id/c72").click()
time.sleep(10)
driver.find_element_by_id("com.tencent.mm:id/blj").clear()
driver.find_element_by_id("com.tencent.mm:id/blj").send_keys("xxxxx")# 用户名
driver.find_element_by_id("com.tencent.mm:id/gl").send_keys("xxxxxx")# 密码
driver.find_element_by_id("com.tencent.mm:id/a9w").click()# 登录
driver.implicitly_wait(30)
driver.find_element_by_class_name("android.widget.Button").click()
time.sleep(40)
driver.find_element_by_id("com.tencent.mm:id/adc").click()
time.sleep(10)
driver.find_element_by_id("com.tencent.mm:id/a2_").send_keys("http://m.ucar.com")
driver.implicitly_wait(10)
driver.find_element_by_id("com.tencent.mm:id/a2f").click()# 点击发送按钮
driver.implicitly_wait(60)
driver.find_element_by_id("com.tencent.mm:id/i_").click()# 点击地址,跳转至首页
#driver.implicitly_wait(100)
time.sleep(20)
print driver.contexts
'''切换到 H5 页面的 webdriver'''
driver.execute(MobileCommand.SWITCH_TO_CONTEXT,{"name":"WEBVIEW_com.tencent.mm:tools"})
driver.implicitly_wait(30)
'''以下部分是 webview 页面的操作'''
driver.find_element_by_xpath('//*[@id="pro-touch"]/li[1]/div[2]/p[1]').click()