[英]Issue using xpath with appium for native android apps
I am having an issue with using xpath in my scripts. 我在脚本中使用xpath时遇到问题。 When I use the Appium inspector to locate and element using this xpath "//android.widget.TextView[@text='My Messages']" the inspector locates it with no problems.
当我使用Appium检查器使用此xpath “ //android.widget.TextView[@text='My Messages']”定位和元素时,检查器可以毫无问题地找到它。 But when I try to use that xpath in my code like this
但是当我尝试像这样在我的代码中使用该xpath时
driver.findElement(By.xpath("//android.widget.TextView[@text='My Messages']")).click();
I get and error message that says 我收到并显示错误消息
org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.
org.openqa.selenium.NoSuchElementException:使用给定的搜索参数无法在页面上找到元素。 (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 20.16 seconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '2.42.2', revision: '6a6995d31c7c56c340d6f45a76976d43506cd6cc', time: '2014-06-03 10:52:47' System info: host: 'C02P98XHG3QD', ip: '127.0.0.1', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.5', java.version: '1.7.0_79' Session ID: 0701451b-c82d-7899-6030-099e74bc9fd4 Driver info: io.appium.java_client.android.AndroidDriver
(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:20.16秒有关此错误的文档,请访问: http ://seleniumhq.org/exceptions/no_such_element.html构建信息:版本:'2.42.2 ',修订版:'6a6995d31c7c56c340d6f45a76976d43506cd6cc',时间:'2014-06-03 10:52:47'系统信息:主机:'C02P98XHG3QD',ip:'127.0.0.1',操作系统名称:'Mac OS X',os .arch:'x86_64',os.version:'10 .9.5',java.version:'1.7.0_79'会话ID:0701451b-c82d-7899-6030-099e74bc9fd4驱动程序信息:io.appium.java_client.android.AndroidDriver
I am not quite sure what I am doing wrong. 我不太确定自己在做什么错。 Am I doing something wrong, or could this be an issue with Appium.
我做错什么了吗,或者这可能是Appium的问题。 I am currently using version 1.4.8
我目前正在使用1.4.8版本
Try to use name. 尝试使用名称。 Use this:
用这个:
driver.findElement(By.xpath("//*[@class='android.widget.TextView' and @text='My Messages']")).click();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.