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

2024-01-11

我无法使用 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 

任何人帮助克服这个将不胜感激?


使用完整的资源 ID ...这对我有用...

下面的行对我有用...... driver.findElement(MobileBy.id("com.android.packageinstaller:id/permission_allow_button")).click();

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

  • 如何跨工作区保存 E​​clipse 启动配置文件?

    当我复制 Eclipse 项目目录时 它包含 classpath 和 project 文件 这样当我将同一目录带到另一个 Eclipse 实例时 我不必设置我的构建路径等 假设所有资源都包含在在项目中 而不是外部 但是 此过程不会导致启动配
  • 使用java将文件从GCS存储桶传输到SFTP服务器

    我能够从 GCS 存储桶读取文件 但所有库都喜欢jsch将文件传输到 SFTP 服务器时会查找文件路径 而不是内存中的文件 我不想将从GCS读取的文件写入磁盘 如何将内存中的文件传输到SFTP 我假设您想上传内存中的数据 JSch 实际上有
  • 如何更改使用 Google ReCaptcha 版本 2 时的错误消息?

    当为 Google ReCaptcha 版本 2 选择多张照片时 会显示以下错误消息 需要多个正确的解决方案 请解决更多 如何将错误消息更改为我网站上的自定义消息 这是图像 我认为不可能在服务器端 在谷歌 进行 这可以在客户端通过利用 js
  • SpannableString 中的 URLSpan

    我正在使用这个例子SpannableString http developer android com resources samples ApiDemos src com example android apis text Link ht
  • java代码的等效vb代码

    谁能告诉我这段Java代码到底做了什么 SecureRandom random SecureRandom getInstance SHA1PRNG byte bytes new byte 20 synchronized random ran
  • 为什么我用Java计算的结果是错误的?

    我使用这段代码来计算一些东西 但几乎在所有情况下结果都是 0 0 为什么 编译器中没有警告或错误 private void jButton1ActionPerformed java awt event ActionEvent evt try
  • 应返回带有 html 代码的字符串的支持 bean 属性返回空字符串

    我的支持 bean 中有一个返回 html 代码的属性 public String getHtmlPrevisualizar return Hello world 我想要做的是在 iframe 中显示这个 html 代码 我用 JavaSc
  • 选择活动时运行时崩溃

    首先我想说我几乎没有 Android 经验 这是我在 Android 中的第一个项目 而且我的老师不太擅长教学 所以我对任何过度的无知表示歉意 在进一步讨论之前先解释一下 我的应用程序的目标本质上是能够记录您在某些活动上花费了多少时间 记录
  • 嵌套异常是java.lang.NoClassDefFoundError:无法初始化类org.springframework.jdbc.support.SQLErrorCodesFactory

    我正在使用 spring 和 jdbctemplate 编写一个应用程序 但是我遇到了以下错误 org springframework web util NestedServletException Handler processing f
  • RecyclerView 来自 Firebase 的部分和数据

    您好 我正在开发一个应用程序 在其中我必须使用 Firebase 填充数据回收器视图 准备就绪 现在我想做的是用 data firebase 填写一个 recyclerview 但有一些部分将成为托管 data firebase 的父级 我
  • 访问 JAR 资源

    我有一个jar包含我想要分发的资源 主要是缓存 日志记录等配置 的文件 我对这些资源的相对路径有问题 所以我做了我在另一个 stackoverflow 问题中发现的问题 该问题说这是一种有效的方法 ClassInTheSamePackage
  • 我们可以将请求分派到 servlet 内的 HTML

    这可能吗 RequestDispatcher rd request getRequestDispatcher index html rd forward request response 是的 您可以将请求分派到 HTML 页面
  • 如何在两种不同模式、两种布局中设置方向?

    我有一个叫做Main XML我将方向设置为纵向AndroidManifest xml 我也为 Honeycomb 设计了这个布局并将其放置在layout xlarge mdpi文件夹 但我想使用Main XML in layout xlar
  • 为什么我得到:没有有效的 JFX 运行时

    我有一个使用 java 1 6 编译并使用 jnlp webstart 运行的现有应用程序 如果我使用 JRE 1 6 从客户端运行此应用程序 一切都会很好 但是 当我使用 java JDK 7 编译代码并使用 JRE 1 7 67 运行客
  • 在 Android(JB 上)中,如何向自定义丰富通知添加操作?

    我一直在使用 Jelly Bean 中新的丰富通知 当我使用模板设置新通知时 一切都按预期工作Notification BigPictureStyle Notification BigTextStyle or Notification In
  • 访问影子 DOM 中的元素

    是否有可能查找 Shadow DOM 中的元素与蟒蛇硒 示例用例 我有这个input with type date
  • Android 通知上有按钮

    我正在尝试使用 2 个按钮发出通知 一个带我回到活动 另一个将其关闭 有谁知道如何捕获按钮单击事件 请记住活动已暂停 我很高兴发布它 经过一夜的工作 我发现了一些东西 那么 我们开始吧 1 为您的通知创建 xml 布局文件 2 使用Noti
  • StableArrayAdapter 与 ArrayAdapter

    我正在看这个ListView教程 列表视图教程 http www vogella com tutorials AndroidListView article html 我想知道创建自己的更好ArrayAdapter 而不仅仅是使用和Arra
  • 如何通过 Selenium 内部的文本查找按钮(Python)?

    我有以下三个按钮 我不知道如何获取其中的文本 例如异常值 我试过browser find element by link text Outliers click 但出现 无法找到元素 错误 我该怎么做 See find element by
  • 应用服务器如何注入私有字段?

    我看到这个问题 注入私有 包或公共字段或提供 setter https stackoverflow com questions 2021716 inject into private package or public field or p

随机推荐