我正在尝试编写使 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.
`
我不确定是什么问题,有人可以帮助我吗?
答案 0 :(得分:0)
使用以下xpath:
driver.findElement(By.xpath("//*[contains(@id,'photo_image_view')]")).click();