appium v1.13.0使用问题记录

appium v1.13.0使用问题记录,第1张

1Command 'E\:\\Development\\Android\\SDK\\platform-tools\\adbexe -P 5037 -s 127001\:62001 shell getprop robuildversionrelease' exited with code 3221226356'; Stderr: ''; Code: '3221226356

原因:adb版本问题,在cmd执行adb version命令发现adb的版本为2900-XXXX

解决方法:升级adb版本,可通过Android studio>tools>sdk manager>Appearance&Behavior > System Setting >Android SDK>SDK tools升级Android SDK Platform-Tools 到2902,adb版本即升级成功,问题解决

2页面从首页切换到第二个页面后,无法定位元素,使用selfdriverpage_source方法获取页面信息无反应。使用XPATH="//"查找元素。发现得到的元素是首页的元素

原因:Android 70切换Activity的bug,需要使用UiAutomator2测试

解决方法:selfdesired_caps['automationName'] ='UiAutomator2'

3切换UiAutomator2后,adbexe -P 5037 -s 1d6f926c shell pm install /data/local/tmp/appium_cache/56abf1bf10f6562619a2dd8fb060718e27c4cb28apk命令执行失败

原因:手动在cmd执行命令,返回Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install ioappiumuiautomator2server without first uninstalling],但实际上手机上找不到该apk。使用adb shell pm list packages 发现package: ioappiumuiautomator2server

解决方法:手动执行adb uninstall package: ioappiumuiautomator2server卸载

The extensive Android SDK allows you to do many great things with particular views like the WebView for displaying webpages on Android powered devices

Android SDK 的扩展通过使用特定的view允许你做许多事情比如WebView用来在Android手机上展示网页

As of lately while I was experimenting with the Android SDK I was using a WebView in one of my activities

最近我在体验Android SDK的时候在一个Activity中用到了WebView

From that particular WebView I needed to know the ContentHeight but also the ContentWidth

从WebView我不但想要知道ContentHeight还想知道ContentWidth

Now getting the contentHeight is easy like so:

现在的情况是获取contentHeight很easy如下

webviewgetContentHeight();

Unfortunately getting the contentWidth from a WebView is rather more difficult since there is not a simple method like:

不幸的是从一个WebView获取contentWidth是相当困难因为SDK中没有一个像这样的方法

// THIS METHOD DOES NOT EXIST!

webviewgetContentWidth();

There are ways to get the contentWidth of the rendered HTML page and that is through Javascript If Javascript can get it for you then you can also have them in your Java code within your Android App

当然是有方法获取contentWidth的就是通过Javascript来获取如果你能够支持Javascript那么你就可以在你的Android 程序中使用java代码来获取宽度

By using a JavascriptInterface with your WebView you can let Javascript communicate with your Android App Java code by invoking methods on a registered object that you can embed using the JavascriptInterface

通过在你的WebView中使用JavascriptInterface通过调用你注册的JavascriptInterface方法可以让Javascript和你的Android程序的java代码相互连通

So how does this work

怎么做呢?

For a quick example I created a simple Activity displaying a webview that loads a webpage wich displays a log message and a Toast message with the contentWidth wich was determined using Javascript Note that this happens AFTER the page was finished loading because before the page is finished loading the width might not be fully rendered Also keep in mind that if there is content loaded asynchronously that it doesnt affect widths (most likely only heights will be affected as the width is almost always fully declared in CSS files unless you have a % width webpage)

搭建一个快速的例子创建一个简单的展示webView的Activity一个LogCat消息一个Toast消息用来显示我们通过 Javascript获取的宽度注意这些会在网页完全加载之后显示因为在网页加载完成之前宽度可能不能够正确的获取到同时也要注意到如果是异 步加载这并不影响宽度(最多高度会受影响因为宽度总是在CSS文件中做了完全的定义除非在网页中你用了%宽度)

Below is the code of the Activity Mainjava:

下面的代码是Activity的代码

package compimmosandroidsampleswebviewcontentwidth;

import androidappActivity;

import androidosBundle;

import androidutilLog;

import androidwebkitWebView;

import androidwebkitWebViewClient;

import androidwidgetToast;

publicclass Main extends Activity {

privatefinalstatic String LOG_TAG = "WebViewContentWidth";

privatefinal Activity activity = this;

privatestaticint webviewContentWidth = ;

privatestatic WebView webview;

/ Called when the activity is first created /

@Override

publicvoid onCreate(Bundle savedInstanceState) {

superonCreate(savedInstanceState);

setContentView(Rlayoutmain);

webview = (WebView) findViewById(Ridwebview);

webviewgetSettings()setJavaScriptEnabled(true);

webviewsetSaveEnabled(true);

webviewaddJavascriptInterface(new JavaScriptInterface() "HTMLOUT");

webviewsetWebViewClient(new WebViewClient() {

@Override

publicvoid onPageFinished(WebView view String url) {

webviewloadUrl("javascript:windowHTMLOUTgetContentWidth(documentgetElementsByTagName(html)[]scrollWidth);");

}

});

webviewloadUrl(";);

}

class JavaScriptInterface {

publicvoid getContentWidth(String value) {

if (value != null) {

webviewContentWidth = IntegerparseInt(value);

Logd(LOG_TAG "Result from javascript: " + webviewContentWidth);

ToastmakeText( activity

"ContentWidth of webpage is: " +

webviewContentWidth +

"px" ToastLENGTH_SHORT)show();

}

}

}

}

Below is the XML layout used with the Activity wich only contains a simple WebView:

下面是Activity的Layout主要就是一个简单的WebView

<xml version="" encoding="utf">

<LinearLayout

xmlns:android=";

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

<WebView android:id="@+id/webview"

android:layout_width="fill_parent"

android:layout_height="fill_parent" />

</LinearLayout>

AndroidManifestxml layout:

AndroidManifestxml代码

<xml version="" encoding="utf">

<manifest

xmlns:android=";

package="compimmosandroidsampleswebviewcontentwidth"

android:versionCode="" android:versionName="">

<application android:icon="@drawable/icon"

android:label="@string/app_name">

<activity android:name="Main"

android:label="@string/app_name">

<intentfilter>

<action android:name="androidintentactionMAIN" />

<category

android:name="androidintentcategoryLAUNCHER" />

</intentfilter>

</activity>

</application>

<usessdk android:minSdkVersion="" />

<usespermission android:name="androidpermissionINTERNET" />

</manifest>

You can also download the full source of Android Application WebViewContentWidth!

转载

长青版WebView2运行时将作为Windows 11 *** 作系统的一部分包含在内。但是在Windows 11之前(Win10、Win81、Win7等),某些设备可能未预安装WebView2运行时。在桌面程序(WinForm、WPF、WinUI、Win32)安装、更新、启动后或创建 WebView2对象之前,程序可以自动执行此检查。通过检查注册表项或调用 API 来检查客户端电脑中是否已经安装了 WebView2 运行时,并在缺少时自动安装它。

检测方法1 检查注册表

在以下两个注册表位置检查 pv (REG_SZ) WebView2 运行时的 regkey。

regkey HKEY_LOCAL_MACHINE 用于 每台计算机 安装。

regkey HKEY_CURRENT_USER 用于 按用户 安装。

对于 WebView2 应用程序,必须至少存在其中一个具有大于 0000 的版本并对其进行定义。 如果两个 regkey 都不存在,或者仅存在其中一个 regkey,但其值为 null空字符串或 0000,则表示未在客户端上安装 WebView2 运行时。 检查这些 regkey 以检测是否安装了 WebView2 运行时,并获取 WebView2 运行时的版本。 在以下两个位置找到 pv (REG_SZ) 。

在手机浏览器使用swipe、scroll等手机特有行为时,因为默认context是WEBVIEW,所有一定要切换回NATIVE_APP才可以使用。

python:

12

driverswitch_tocontext("NATIVE_APP") driverswipe(300, 970, 300, 20)

可能是程序在旧版本开放用的接口与新版本的接口名字不一样导致了调用失败,因为这个名字的类在原来的路径下没有找到。

你可以通过指定编译器用的包的方式让软件重新运行,就是改编译器的环境变量为旧版的包

以上就是关于appium v1.13.0使用问题记录全部的内容,包括:appium v1.13.0使用问题记录、如何获得webview的内容、webview2找不到运行时等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9775125.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-01
下一篇2023-05-01

发表评论

登录后才能评论

评论列表(0条)

    保存