环境:
问题:在微信中无法切换到公众号的 html 5
代码:
#coding=utf-8
from appium import webdriver
from time import sleep
desired_caps = {
# 'automationName':'Selendriod',
'platformName':'Android',
'platformVersion':'4.2',
'deviceName':'NX403A',
'appPackage':'com.tencent.mm',
'appActivity':'com.tencent.mm.ui.LauncherUI',
'unicodeKeyboard' : 'true',
'resetKeyboard' : 'true'
}
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
print("打开微信,进入聊天消息列表界面")
driver.implicitly_wait(15)
def button_search(driver):#点击搜索按钮
driver.find_element_by_accessibility_id('搜索').click()
# driver.find_element_by_xpath("//android.widget.TextView").click()
def button_input(driver):#点击搜索,输入关键字
driver.find_element_by_xpath("//android.widget.EditText[contains(@text,'搜索')]").send_keys("沈阳中电")
def Public_number(driver): #点击“沈阳中电公众号”
driver.find_element_by_xpath("//android.widget.TextView[contains(@text,'沈阳中电健云科技有限公司')]").click()
def prompt(driver):#位置提醒信息,点击确定
driver.find_element_by_xpath("//android.widget.Button[contains(@text,'确定')]").click()
def switch_input_method(driver): #切换到消息输入框
driver.find_element_by_accessibility_id('消息').click()
def cut_import(driver):#输入消息(test)点击发送
driver.find_element_by_xpath("//android.widget.EditText[contains(@index,'0')]").send_keys('test')
sleep(2)
driver.find_element_by_xpath("//android.widget.Button[contains(@text,'发送')]").click()
def cut_menu(driver):#切换菜单
driver.find_element_by_accessibility_id('服务按钮').click()
def register(driver):#挂号,点击菜单
driver.find_element_by_xpath("//android.widget.TextView[contains(@text,'挂号')]").click()
driver.find_element_by_xpath("//android.widget.TextView[contains(@text,'挂号')]").click()
def more_service(driver):#一级-更多服务
driver.find_element_by_xpath("//android.widget.TextView[contains(@text,'更多服务')]").click()
driver.find_element_by_xpath("//android.widget.TextView[contains(@text,'注册/登录')]").click()
def view_switch(driver):
contexts = driver.contexts
for context in contexts:
print(context)
# driver.switch_to.context("NATIVE_APP")
driver.contexts("WEBVIEW",list)
send = driver.find_element_by_xpath('//*[@id="login_btn"]')
send.click()
# print(driver.current_context)
def quit(driver):
driver.close_app()
button_search(driver)
print('点击搜索按钮')
sleep(5)
button_input(driver)
print('输入关键字-中电-搜索')
Public_number(driver)
print('点击搜索的公众号')
switch_input_method(driver)
print('切换输入文字')
cut_import(driver)
print('输入文字消息')
cut_menu(driver)
print('切换到菜单')
register(driver)
print('点击挂号菜单')
more_service(driver)
sleep(5)
view_switch(driver)
quit(driver)
contexts(driver)
问题截图: