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()
  • 相关阅读:
    flex布局简介
    未知宽高图片垂直居中
    网页设计中颜色应用
    webstorm10 注册码
    webapp尺寸
    【转】 svn 错误 以及 中文翻译
    css实现一个写信的格式
    使用::before和::after来完成尖角效果
    AI (Adobe Illustrator)详细用法(五)
    AI (Adobe Illustrator)详细用法(四)
  • 原文地址:https://www.cnblogs.com/guoke1001/p/13040741.html
Copyright © 2011-2022 走看看