zoukankan      html  css  js  c++  java
  • Appium(四) WebView切换

                                                                                                      WebView切换


    1、目前app基本都是混合型的,有原生的native_app,也有webview,使用appium测试的时候,遇到webview的时候需要切换上下文,切换后就可以使用css等方式定位

    2、如何获取app的上下文

    • self.driver.context 获取当前窗口的context,
    • self.driver.contexts,获取当前窗口的context,返回的是list

    3、切换webview:

    • self.driver.switch_to.context("xxx")切换到对应的webview

    4、如何判断是否是webview:

    • 使用uiaumator的时候class:会包含webview/view,如android.webkit.WebView
    • 使用self.driver.context/self.driver.contexts获取到的context包含如:WEBVIEW_com.xxx等就是

    5、如何从webview切换到原生app:

    • self.driver.switch_to.context("NATIVE_APP")

    6、代码:

    1  def get_webview(self,webname):
    2         webviews=self.driver.contexts
    3         for web in webviews:
    4             if webname in web:
    5                 return webname
    6     def swich_webview(self):
    7         self.driver.switch_to.context(self.get_webview("xxxx"))
    8         #切换后可以使用css方式定位
    9         self.driver.find_element_by_css_selector()
  • 相关阅读:
    JSONP跨域的原理解析( 一种脚本注入行为)
    用Navicat_SSH 连接数据库服务器
    ng-repeat && ng-options的故事
    The different between ng-grid & ui-grid
    Web工作原理
    js操作cookies方法
    人生苦短,我用Python(目录)
    哈希算法
    数据结构
    算法入门
  • 原文地址:https://www.cnblogs.com/guoke1001/p/13040741.html
Copyright © 2011-2022 走看看