小程序自动化切换上下文遇到的问题:appium

webview 版本:77.0.3865.120      chromedriver 版本:77.0.3865.40     appium版本:V1.8.1                                                              手机型号:红米k20pro(已经打开微信调试模式)

用的appium已经正常连接到设备打开微信进入小程序切换上下文时报错

1.换了多个版本的chromedirver版本还是不行

2.切换到原生的'NATIVE_APP' 能成功

3.换过华为V20和华为mate手机报错信息显示一样

4.打印出来的conte下有多个不知道怎么回事

请大神们帮忙解

 

代码:

import time

from appium import webdriver

desired_caps = {


    # 设备信息

    'automationName': "uiautomator2",

    'platformName': 'Android',

    'platformVersion': '6',

    'deviceName': 'S4T4ZPOFEIYS85MJ',

    'systemPort': '8200',

    'udid': 'S4T4ZPOFEIYS85MJ',

    'appPackage': 'com.tencent.mm',

    'appActivity': 'com.tencent.mm.ui.LauncherUI',

   'chromeOptions': {'androidProcess': 'com.tencent.mm:appbrand0'}

    # 不要重置应用


    'noReset': True,

    'chromedriverExecutable': 'E:\\h5_chromedriver\\chromedriver.exe',

}


# 声明我们的driver对象


dirvers = webdriver.Remote('http://127.0.0.1:4723''/wd/hub', desired_caps)

dirvers.implicitly_wait(10)

time.sleep(15)

dirvers.find_element_by_xpath("//*[@text='发现']").click()

time.sleep(3)

dirvers.find_element_by_xpath("//*[@text='小程序']").click()

time.sleep(3)

dirvers.find_element_by_xpath("//*[@text='拼多多']").click()

time.sleep(7)

# 打印的contexts结果:       

contexts = dirvers.contexts

print(contexts)
time.sleep(15)

# #切换到webview

dirvers.switch_to.context("WEBVIEW_com.tencent.mm:appbrand0")

 

Pycharm运行时报错信息

C:\Users\Administrator.SC-201908171206\AppData\Local\Programs\Python\Python36-32\python.exe "C:/Users/Administrator.SC-201908171206/Desktop/xiaochengxu/test - 副本.py"


['NATIVE_APP', 'WEBVIEW_com.tencent.mm:appbrand0', 'WEBVIEW_com.tencent.mm:tools', 'WEBVIEW_com.tencent.mm:toolsmp', 'WEBVIEW_com.tencent.mm']


Traceback (most recent call last):

  File "C:/Users/Administrator.SC-201908171206/Desktop/xiaochengxu/test - 副本.py", line 42, in <module>

    dirvers.switch_to.context("WEBVIEW_com.tencent.mm:appbrand0")

  File "C:\Users\Administrator.SC-201908171206\AppData\Local\Programs\Python\Python36-32\lib\site-packages\appium\webdriver\switch_to.py", line 31, in context

    self._driver.execute(MobileCommand.SWITCH_TO_CONTEXT, {'name': context_name})

  File "C:\Users\Administrator.SC-201908171206\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 201, in execute

    self.error_handler.check_response(response)

  File "C:\Users\Administrator.SC-201908171206\AppData\Local\Programs\Python\Python36-32\lib\site-packages\appium\webdriver\errorhandler.py", line 29, in check_response
    raise wde
  File "C:\Users\Administrator.SC-201908171206\AppData\Local\Programs\Python\Python36-32\lib\site-packages\appium\webdriver\errorhandler.py", line 24, in check_response

    super(MobileErrorHandler, self).check_response(response)

  File "C:\Users\Administrator.SC-201908171206\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 181, in check_response

    raise exception_class(message, screen, stacktrace)


selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Did not get a valid response object. Object was: {"value":{"build":{"version":"77.0.3865.40 (f484704e052e0b556f8030b65b953dce96503217-refs/branch-heads/3865@{#442})"},"message":"ChromeDriver ready for new sessions.","os":{"arch":"x86_64","name":"Windows NT","version":"10.0.18363"},"ready":true}}


 

 

 

appium日志记录

 

问题解决了,我的情况跟你一样,也不知道怎么解决呢