Appium 微信里面切换 web view 无法切换

玄月指光 · 2016年04月20日 · 最后由 迷途的小鸭子 回复于 2016年07月23日 · 1301 次阅读

环境:

  1. MAC 10.11.4
  2. python3.5 appium 1.4.3
  3. IDE PyCharm
  4. Android 4.2.2

问题:在微信中无法切换到公众号的 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)

问题截图:

共收到 9 条回复 时间 点赞

请使用 markdown

被屏蔽了,WHY?我觉得这是个很好的帖子呀~

楼主问题解决了么,我也遇到了同样的问题。。。

楼主问题解决了吗?

#2 楼 @jamie why 的原因看不出么。。和内容没什么关系。

清缓存可以,我每次清完缓存都能正常!

#6 楼 @hanzo000 清微信缓存么?

@hanzo000 清除缓存就可以?你是按照提问者的方式写的代码么

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册