没有这样的元素异常,但元素显然存在

问题描述 投票:0回答:1

我正在尝试编写自动化Android应用程序的代码来完成你用手指做的一切。

现在的目标是让它选择一张图片。我键入了这一行,因此它通过uiautomatorviewer的resource-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个回答
0
投票

使用以下xpath:

driver.findElement(By.xpath("//*[contains(@id,'photo_image_view')]")).click();
© www.soinside.com 2019 - 2024. All rights reserved.