class DianShang(object):

    def SetUp(self):
        desired_caps = Desired_Capabilities.startdevices()
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
        print u"设备配置成功"
        sleep(5)
        homeDshang = self.driver.find_elements_by_class_name("android.view.View")
        homeDshang[1].click()
        sleep(8)
        print self.driver.context
        self.driver.switch_to.context("WEBVIEW_com.android.browser")

背景:
界面时 H5 做得商品列表界面, 用 uiautomatorview 获取到的是一个整个屏幕
尝试切换到 webview 时, 在商品列表界面打印出来的只有 native_app,还是无法定位到具体的商品

打印出的信息报错:

ATIVE_APP
Traceback (most recent call last):
  File "C:/Pycharm/ManBoker/HomeDShang/ArticleList.py", line 28, in <module>
    DianShang().SetUp()
  File "C:/Pycharm/ManBoker/HomeDShang/ArticleList.py", line 21, in SetUp
    self.driver.switch_to.context("WEBVIEW_com.android.browser")
  File "D:\Python27\lib\site-packages\appium\webdriver\switch_to.py", line 31, in context
    self._driver.execute(MobileCommand.SWITCH_TO_CONTEXT, {'name': context_name})
  File "D:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "D:\Python27\lib\site-packages\appium\webdriver\errorhandler.py", line 27, in check_response
    raise NoSuchContextException(wde.msg, wde.screen, wde.stacktrace)
appium.common.exceptions.NoSuchContextException: Message: No such context found.

Process finished with exit code 1

问题:
怎么把界面转换到 webview?


↙↙↙阅读原文可查看相关链接,并与作者交流