zoukankan      html  css  js  c++  java
  • 【appium】解决 打开第二个webview识别第一个webview元素

    问题:

     hybrid app进行appium自动化时,都会进行contexts切换到webview来进行事件点击。但如果打开了第二个webview的情况下并且webview是新开页面,可能会识别成之前的webview内容。导致无法进行事件点击。

    例:

    解决方法:

     切换到新的webview页面时候,先进行切换回native的context,此时杀掉chromedriver进行,再次切换webview context让chromedriver重新获取新的webview。

    注意:不要在webview context情况下杀掉chromedriver,会导致页面关闭。

    更新:appium1.5版本以上可以设置

    recreateChromeDriverSessions=true  不需要手动kill。

     

    杀掉chromedriver:

    pkill -9 chromedriver
    

    附带切换context代码

    def switch_context(self, context="WEBVIEW_xxxx"):
        context = context.upper()
        contexts = self.driver.contexts
        for con in contexts:
            if context in con and context.find('WEBVIEW') != -1:
                print 'switch webview'
                self.driver.switch_context(con)
                res = self.driver.current_context
                return True if context in res else False
            elif context in con and context.find('NATIVE') != -1:
                print 'switch native'
                self.driver.switch_context(con)
                os.system('pkill -9 chromedriver')
                res = self.driver.current_context
                print res
                return True if context in res else False
        return SwitchContextError
    
    
    def switch_content_default(self):
        time.sleep(3)
        self.driver.switch_context('NATIVE_APP')
        os.system('pkill -9 chromedriver')
        for con in self.driver.contexts:
            if con.find('WEBVIEW') != -1:
                self.driver.switch_context(con)
                return True
        return SwitchContextError
    
  • 相关阅读:
    cookie 和session 的区别
    求职面试技巧
    php setcookie(name, value, expires, path, domain, secure) 参数详解
    (输出缓冲)函数的妙用
    linux下忘记mysql root密码解决办法
    php导入导出
    nginx的基本配置和虚拟主机的配置
    实战练习235页
    接口练习
    总结构建子类对象时的顺序
  • 原文地址:https://www.cnblogs.com/dapped/p/7799027.html
Copyright © 2011-2022 走看看