当前位置: 首页 > 面试题库 >

无法使用Appium在Android的权限对话框中单击“允许”按钮

松飞翮
2023-03-14
问题内容

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

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控制台中的错误:

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日志

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

任何人为克服这一问题的帮助将不胜感激?


问题答案:

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

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


 类似资料:
  • 我已经根据新材料设计集成了Marshmallow权限对话框,但权限对话框正在模拟器上工作,而不是在真实设备上工作。而且我也没有得到任何错误。任何人都可以帮我吗? 我正在使用以下代码:- ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.pe

  • 我刚开始在appium测试。我能够设置一切并运行测试。我使用UiAutomatorViewer访问了一些按钮,现在我需要单击一个按钮,但我只是得到了cont-desc。我尝试了以下XPath,但最终得到一个错误。任何帮助都会很好。 @findby(xpath=“//*[@contentdescription='登录  登录']”) driver.findElement(by.xpath(“//an

  • 当我单击按钮时,会显示一个引导模式弹出窗口。我尝试使用下面的恶作剧功能单击确定或取消按钮,但都不起作用。要么功能不起作用,要么单击外部。 单击“释放”时,将有一个带有OK和取消按钮的引导模式,可以通过屏幕截图进行验证。尝试使用以下命令单击OK按钮。 第页。查找(“.btn.procedue.btn primary”)。触发器(“单击”) 单击链接(“确定”) 第页。执行\u脚本(“$”(“.btn

  • 当用户单击返回按钮时,我正在尝试退出应用程序,让它在单击是按钮时显示对话框是/否按钮,让它退出应用程序,包括注册活动,假设您在主活动上。 这是我的代码,但它不工作 单击主活动上的“后退”按钮时 如何从主活动退出应用程序,包括在是按钮单击对话框上的注册活动

  • 问题内容: 我正在使用 selenium2 beta 。我试图单击按钮,这将打开文件附件对话框。但是当我单击它时,什么也没有发生。 仅使用selenium而不是selenium2我可以轻松单击它。 问题答案: 我猜问题只是在使用Internet Explorer时出现,因为IE和FF处理文件输入略有不同:在FF中,您可以单击按钮或字段以调用“打开”对话框,而在IE中,您可以单击按钮或 双击单击 该