【问题标题】:No such element exception but the element is clearly there没有这样的元素例外,但元素显然存在
【发布时间】:2019-03-13 22:14:46
【问题描述】:

我正在尝试编写代码来自动化 android 应用程序来完成您用手指可以完成的所有操作。

现在的目标是让它选择一张图片。我输入了这一行,所以它通过来自 uiautomatorviewer 的资源 ID 选择元素。

driver.findElement(By.id("com.offerup:id/photo_image_view")).click();

但是当我运行我的代码时,这就是我的 Appium 服务器日志中显示的内容。

`[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.offerup:id/photo_image_view' using 'ID' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.offerup:id/photo_image_view]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.offerup:id/photo_image_view' using 'ID' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.offerup:id/photo_image_view]
[AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Matched JSONWP error code 7 to NoSuchElementError
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":7,"value":"No element found"}
[W3C (3ce51f1a)] Encountered internal error running command: NoSuchElementError: An element could not be located on the page using the given search parameters.

`

我不知道是什么问题,谁能帮帮我?

【问题讨论】:

    标签: java android automation appium nosuchelementexception


    【解决方案1】:

    使用以下 xpath:

    driver.findElement(By.xpath("//*[contains(@id,'photo_image_view')]")).click();
    

    【讨论】:

    • 没有成功,我的控制台在它想运行这个命令时停止执行代码,它甚至没有给我一个异常。
    猜你喜欢
    • 2021-08-22
    • 2021-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-29
    • 2013-12-01
    相关资源
    最近更新 更多