无法使用 Appium 在 Android 的权限对话框中单击允许按钮 [英] Can't click Allow button in permission dialog in Android using Appium

查看:17
本文介绍了无法使用 Appium 在 Android 的权限对话框中单击允许按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用 Appium+Java 在 Android 中的权限对话框中点击拒绝或允许按钮.在点击这些按钮之前,我需要添加任何功能吗?代码如下:

I am unable to tap on Deny or Allow buttons on the permissions dialog in Android using Appium+Java. Do I need to add any capabilities before going to tap on those buttons? Below is the code:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "ASUS_Z00LD");
capabilities.setCapability("platformVersion", "6.0");
capabilities.setCapability("app","<AppPath>");
capabilities.setCapability("browserName", "");
AndroidDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        Thread.sleep(10000);
driver.findElement(MobileBy.id("permission_allow_button")).click();

以下是 Eclipse 控制台中的错误:

Below is error in Eclipse console:

org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)

以下是 Appium 日志:

Below is the Appium log:

info: [debug] Responding to client with success: {"status":0,"value":{"platform":"LINUX","browserName":"","platformVersion":"6.0.1","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"app":"/Users/Shiva/Documents/workspace/AndroidPractice/APK/****_Android.apk","browserName":"","platformName":"Android","deviceName":"ASUS_Z00LD","platformVersion":"6.0"},"app":"/Users/Shiva/Documents/workspace/AndroidPractice/APK/****_Android.apk","platformName":"Android","deviceName":"FAAZCY127084"},"sessionId":"b64fd5af-3de5-4299-a2d4-1948fc8e883e"}
info: <-- GET /wd/hub/session/b64fd5af-3de5-4299-a2d4-1948fc8e883e 200 1.534 ms - 625 {"status":0,"value":{"platform":"LINUX","browserName":"","platformVersion":"6.0.1","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"app":"/Users/Shiva/Documents/workspace/AndroidPractice/APK/****_Android.apk","browserName":"","platformName":"Android","deviceName":"ASUS_Z00LD","platformVersion":"6.0"},"app":"/Users/Shiva/Documents/workspace/AndroidPractice/APK/****_Android.apk","platformName":"Android","deviceName":"FAAZCY127084"},"sessionId":"b64fd5af-3de5-4299-a2d4-1948fc8e883e"}

info: --> POST /wd/hub/session/b64fd5af-3de5-4299-a2d4-1948fc8e883e/element {"using":"id","value":"permission_allow_button"}

info: [debug] Waiting up to 0ms for condition

info: [debug] Pushing command to appium work queue: ["find",{"strategy":"id","selector":"permission_allow_button","context":"","multiple":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"permission_allow_button","context":"","multiple":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding permission_allow_button using ID with the contextId:  multiple: false
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.****.****:id/permission_allow_button]

info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=android:id/permission_allow_button]

info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=permission_allow_button, INSTANCE=0]

info: [debug] [BOOTSTRAP] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
info: [debug] [BOOTSTRAP] [debug] Finding permission_allow_button using ID with the contextId:  multiple: false
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.****.****:id/permission_allow_button]

info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=android:id/permission_allow_button]

info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=permission_allow_button, INSTANCE=0]

info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":7,"value":"No element found"}

info: [debug] Condition unmet after 178ms. Timing out.

info: [debug] Responding to client with error: {"status":7,"value":{"message":"An element could not be located on the page using the given search parameters.","origValue":"No element found"},"sessionId":"b64fd5af-3de5-4299-a2d4-1948fc8e883e"}
info: <-- POST /wd/hub/session/b64fd5af-3de5-4299-a2d4-1948fc8e883e/element 500 181.769 ms - 195 

有人帮助克服这个问题吗?

Anyone's help to overcome this would be appreciated?

推荐答案

使用下面的代码片段,我可以点击所有允许按钮来获得权限.

With the below snippet I am able to click on all the allow buttons to get the permissions.

while (driver.findElements(MobileBy.xpath("//*[@class='android.widget.Button'][2]")).size()>0) {
    driver.findElement(MobileBy.xpath("//*[@class='android.widget.Button'][2]")).click();
}

这篇关于无法使用 Appium 在 Android 的权限对话框中单击允许按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆