无效的选择异常,而在酱实验室运行Appium测试

问题描述:

我使用XPath是一个Android应用程序:无效的选择异常,而在酱实验室运行Appium测试

//android.widget.EditText[contains(@resource-id,'etPass')]

此XPath工作正常,当我在真机或虚拟机在本地运行测试。

但是当我在Sauce Labs上运行相同的测试时,它给了我无效的选择器异常。

org.openqa.selenium.InvalidSelectorException: 
An error occurred while searching for an element by XPath. (WARNING: 
The server did not provide any stacktrace information) 
Command duration or timeout: 88 milliseconds 
For documentation on this error, please visit: 
http://seleniumhq.org/exceptions/invalid_selector_exception.html 

当我使用XPath与@text而不是@resource-id,它的工作原理。为什么Sauce Labs不认可@resource-id作为查找xpath的有效属性?

下面是uiautomatorviewer与XML的截图

UiAutomatorViewer screenshot

+0

你试过// android.widget.EditText [包含(@ id,'etPass')]'这个? –

+0

是的,我试过了。它不考虑条件。 因此'//android.widget.EditText[contains(@id,'etPass')]'与'android.widget.EditText'相同。它只是去屏幕上的第一个EditText元素,恰好是用户名框,而不是密码框 – BludShot

+0

@BludShot:请更新与您的代码块和appium检查员屏幕截图的问题提到的元素,以弄清事情 – nullpointer

做正确的方法应使用此:

//android.widget.EditText[contains(@id,'etPass')] //resource-id is not a recognised attribute for selection 

另外,如果你需要具体到选择单元素使用x路径:

//android.widget.EditText[@id='etPass'] // = ensures the value match for specified attribute 
+0

但它不起作用。 '//android.widget.EditText[contains(@id,'etPass')]''返回我的用户名框而不是密码框,因为用户名框是屏幕上的第一个EditText元素。 – BludShot

+0

@BludShot:更新了特定字段的答案 – nullpointer

+0

'//android.widget.EditText[@id='etPass']'也不起作用。 它不会将id视为属性。当我使用任何垃圾值而不是id时,会发生同样的情况,也就是说,它会返回第一个EditText元素 – BludShot