Android Appium(Webdriver.io)无法通过xpath找到元素

Android Appium(Webdriver.io)无法通过xpath找到元素,android,automated-tests,appium,webdriver-io,Android,Automated Tests,Appium,Webdriver Io,我是Appium的新手,所以可能会做错什么 技术:TypeScript+Appium(wd.io)+Jasmine 但我一直坚持接受错误: 茉莉花原木: An element could not be located on the page using the given search parameters ("//android.view.ViewGroup[@resource-id="com.app.dev.debug:id/toolbar"]//android.widget.TextVie

我是Appium的新手,所以可能会做错什么

技术:TypeScript+Appium(wd.io)+Jasmine

但我一直坚持接受错误:

茉莉花原木:

An element could not be located on the page using the given search parameters ("//android.view.ViewGroup[@resource-id="com.app.dev.debug:id/toolbar"]//android.widget.TextView")
Appium日志:

[HTTP] --> POST /wd/hub/session/03ca8b58-7487-4ef6-9b81-8287a23c4a48/element {"using":"xpath","value":"//android.view.ViewGroup[@resource-id=\"com.app.dev.debug:id/toolbar\"]//android.widget.TextView"}
[debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["xpath","//android.view.ViewGroup[@resource-id=\"com.app.dev.debug:id/toolbar\"]//android.widget.TextView","03ca8b58-7487-4ef6-9b81-8287a23c4a48"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.view.ViewGroup[@resource-id=\"com.app.dev.debug:id/toolbar\"]//android.widget.TextView","context":"","multiple":false}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.view.ViewGroup[@resource-id=\"com.app.dev.debug:id/toolbar\"]//android.widget.TextView","context":"","multiple":false}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding '//android.view.ViewGroup[@resource-id="com.app.dev.debug:id/toolbar"]//android.widget.TextView' using 'XPATH' with the contextId: '' multiple: false
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding '//android.view.ViewGroup[@resource-id="com.app.dev.debug:id/toolbar"]//android.widget.TextView' using 'XPATH' with the contextId: '' multiple: false
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":7,"value":"No element found"}
[debug] [AndroidBootstrap] Received command result from bootstrap
[HTTP] <-- POST /wd/hub/session/03ca8b58-7487-4ef6-9b81-8287a23c4a48/element 500 232 ms - 164 

这里出了什么问题?如何使其工作?

在选择器中,您似乎没有提供应该使用哪个“By”来查找元素

请尝试下面的方法

it('test', () =>
  driver.init().element(by.xpath(selector)).getText().then(text => 
expect(text).toBe('myText'))
);
希望这有助于找到解决方案: 添加了.waitForExist(选择器)


您能否提供您的应用程序树?此错误很可能与不正确的selector@PierreBaran,done=)不幸的是,这里没有webdriver.io=\
it('test', () =>
  driver.init().element(by.xpath(selector)).getText().then(text => 
expect(text).toBe('myText'))
);
it('test', () =>
  driver.init().waitForExist(selector).element(selector).getText().then(text => 
expect(text).toBe('myText'))
);