robotframework切换webview(Android)
发布日期:2021-06-23 19:02:52 浏览次数:13 分类:技术文章

本文共 1820 字,大约阅读时间需要 6 分钟。

问题:

在用robot写手机app的自动化时,打开商城商品详情页H5页面立即购买确认支付用例;

需要切换到对应的webview,切换到webview后,点击商品详情页-立即购买,跳转到支付页面,支付确认页面也是H5,

与商品详情页页面的webview一样,此时点击立即购买页面的元素,提示找不到元素,用get source获取商品详情页面源码,

获取到的源码是第一个商品详情页的立即购买页面的源码,所以在商品详情页面执行操作找不到元素。

解决:

在商品详情页面点击立即购买后,先切换回NATIVE_APP,再重新切换回对应的webview(WEBVIEW_aye_com.aye_aye_paste_android),此后就能执行商品详情页面的元素了

步骤:

前提是:debug包,让安卓开发人员在H5页面开启webview的权限:
1.设置webview.setWebContentsDebuggingEnabled(true);
不一定要更改原来的webview继承的父类,先看现在已有的继承父类有没有这个属性,如果有,就先开启就行了;
2.没有webviewsetWebContentsDebuggingEnabled此属性:
就继承:

public class MyActivity  extends CordovaActivity {
CordovaWebView cwv; /** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.init(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { this.appView.setWebContentsDebuggingEnabled(true); } // Set by
in config.xml loadUrl(launchUrl); }}

robotframework代码:

@{contexts} Get Contexts    #获取原生app跟webview的名称Log Many    @{contexts} #打印出原生app跟webview名称${cur_context} Get Current Context #得到当前app内容log ${cur_context} #打印当前app内容名称Switch To Context   WEBVIEW_aye_com.aye_aye_paste_android   #切换到webview${cur_context} Get Current Context #得到当前app内容log ${cur_context} #打印当前app内容名称${page}    Log Source  #获取当前webview的源码log ${page}    #打印当前webview的源码Page Should Contain Text    立即购买    Click Element   xpath=//div[contains(@class,'addPurchase')] #立即购买Wait Until Page Contains    确定  Click Element   xpath=//div[contains(@class,'addPurchase')] #确定Wait Until Page Contains    结算  Click Element   xpath=//a[@class="am-button am-button-warning"] #结算Wait Until Page Contains    Click Elementxpath=//a[@class="am-button am-button-primary"]

原理是:原生APP页面跳转到H5页面(webview),然后再定位xpath;

这里写图片描述

转载地址:https://blog.csdn.net/u014522871/article/details/81504930 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Chrome版本和chrome driver版本对应关系
下一篇:web-based installer、executable installer、embeddable zip

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年03月27日 23时52分07秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章