zoukankan      html  css  js  c++  java
  • appium 处理webview

    打开webview页面 

    chrome://inspect/#devices

     获取webview driver版本

    1、

    2、

    3、

    chenshifengdeMacBook-Pro:ChromeDriver chenshifeng$ adb shell pm list package|grep webview
    package:com.android.webview
    package:org.chromium.webview_shell
    chenshifengdeMacBook-Pro:ChromeDriver chenshifeng$ adb shell pm dump com.android.webview|grep version
          versionCode=373018615 minSdk=21 targetSdk=29
          versionName=74.0.3729.186

     切换native与webview

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    """
    @author:chenshifeng
    @file:test_webview.py
    @time:2020/11/29
    """
    
    from appium import webdriver
    
    
    class TestWebview:
        def setup(self):
            desired_caps = {
                "platformName": "Android",
                "platformVersion": "8.0",
                "automationName": "UiAutomator2",
                "deviceName": "emulator-5554",
                "appPackage": "com.example.android.apis",
                "appActivity": "com.example.android.apis.ApiDemos",
                "chromedriverExecutable": "/Users/chenshifeng/Library/SoftWare/ChromeDriver/chromedriver74",
                # "appActivity": ".common.MainActivity",
                "noReset": True,  # 不重置APP
                # "autoGrantPermissions": True,
                # "skipServerInstallation": True,  # 跳过 uiAutomator2服务器安装
                # "dontStopAppOnReset": True,
                # "skipDeviceInitialization": True,  # 跳过设备初始化
                # "unicodeKeyboard": True,  # 默认启用 Unicode 输入
                # "resetKeyboard": True,  # 与上面合用,可以输入中文
                # "newCommandTimeout": 300
            }
            self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
            self.driver.implicitly_wait(10)
    
        def teardown(self):
            self.driver.quit()
    
        def test_webview(self):
            self.driver.find_element_by_xpath('//*[contains(@text,"Views")]').click()
            print(self.driver.contexts)
    
            self.driver.find_element_by_android_uiautomator('new UiScrollable(new UiSelector().'
                                                            'scrollable(true).instance(0)).'
                                                            'scrollIntoView(new UiSelector().text("WebView").'
                                                            'instance(0));').click()
     
    
            # self.driver.find_element_by_xpath('//*[contains(@text,"Hello World! - 1")]').click()  # 可以与native页面一样处理,但这种方法由于不同的手机渲染的结果不一样,不具有通用性
            print(self.driver.contexts)  # 获取上下文
            self.driver.switch_to.context(self.driver.contexts[-1]) 进入到webview页面
            self.driver.find_element_by_xpath('/html/body/a').click()
    
            # print(self.driver.page_source)
            sleep(5)

    执行结果

    ============================== 1 passed in 32.47s ==============================
    
    Process finished with exit code 0
    PASSED                        [100%]['NATIVE_APP']
    ['NATIVE_APP', 'WEBVIEW_com.example.android.apis']
  • 相关阅读:
    WPF数据绑定之Ado.net的数据库连接绑定
    asp.net 网站js弹出提示后原页面css样式丢失
    Javascript中函数重载的实现
    JavaScript的继承
    WPF数据绑定之4种绑定模式
    Asp.net输出Excel文件并且下载该文件以及某些细节问题解决
    js 验证身份证 带X
    WPF的数据绑定之控件源绑定以及代码方式绑定
    WPF数据绑定之DataContext
    在无cookie模式中,会话话状态的ID将会自动保存在ASP.NET的查询字符串中
  • 原文地址:https://www.cnblogs.com/feng0815/p/14056127.html
Copyright © 2011-2022 走看看