appium如何切換Native和WebView


方法一:

Set<String>contexts=driver.getContextHandles();
driver.context((String)contexts.toArray()[1]);  //選取webview開頭的context

方法二(官方示例):

driver.getContextHandles().forEach((handle) -> {
                if (handle.contains("WEBVIEW")) {
                    driver.context(handle);
                }
            });

此外,好多chromdriver不兼容,我再上傳一個chromdriver--雲盤鏈接如下:

https://pan.baidu.com/s/1dFRTgRZ

 方法三:

public void context_to_webview(AppiumDriver<MobileElement> mdriver) {
        Set<String> ContextHandles = mdriver.getContextHandles();
        LOGGER.info("All ContextHandles :" + ContextHandles);
        if (ContextHandles.size() == 1) {
            LOGGER.info("該web頁未開啟debug狀態");
        } else {
            mdriver.getContextHandles().forEach((handle) -> {
                if (handle.contains("WEBVIEW")) {
                    mdriver.context(handle);
                }
            });

        }
    }

 

原文鏈接:https://testerhome.com/topics/10951


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM