WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

Trouble with xpath with WinAppDriver

Open AmitVerma4HP opened this issue 8 years ago • 4 comments

The objective is to validate that

  1. The correct print queue window is open
  2. The correct print job is queued

Here is the code -

// Ensure you have Correct Print Queue opened Assert.assertNotNull(PrinterQueueSession.findElementByXPath("TitleBar//[starts-with(@value, "HPB8033E")]")); System.out.println("Opened correct printer queue => " +printerName);

//Validate Job Name Assert.assertTrue(PrinterQueueSession.findElementByXPath("ListItem//[starts-with(@Name, "test1 - Notepad")]").get

JSON WireProtocol Logs [debug] [JSONWP Proxy] Proxying [GET /wd/hub/session/7caca227-e70c-473d-ab9e-6b5c26258dce] to [GET http://127.0.0.1:4728/wd/hub/session/B90ADA83-8975-4189-96C1-70240EBE05D2] with body: {} [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] ========================================== [WinAppDriver] [STDOUT] GET /wd/hub/session/B90ADA83-8975-4189-96C1-70240EBE05D2 HTTP/1.1 [WinAppDriver] [STDOUT] Accept: / [WinAppDriver] [STDOUT] Connection: keep-alive [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] Host: 127.0.0.1:4728 [WinAppDriver] [STDOUT] User-Agent: appium [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] HTTP/1.1 200 OK [WinAppDriver] [STDOUT] Content-Length: 128 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {"sessionId":"B90ADA83-8975-4189-96C1-70240EBE05D2","status":0,"value":{"appTopLevelWindow":"0xA06E0","platformName":"Windows"}} [debug] [JSONWP Proxy] Got response with status 200: "{"sessionId":"B90ADA83-8975-4189-96C1-70240EBE05D2","status":0,"value":{"appTopLevelWindow":"0xA06E0","platformName":"Windows"}}" [JSONWP Proxy] Replacing sessionId B90ADA83-8975-4189-96C1-70240EBE05D2 with 7caca227-e70c-473d-ab9e-6b5c26258dce [HTTP] <-- GET /wd/hub/session/7caca227-e70c-473d-ab9e-6b5c26258dce 200 7 ms - 128 [HTTP] --> GET /wd/hub/session/7caca227-e70c-473d-ab9e-6b5c26258dce {} [MJSONWP] Driver proxy active, passing request on via HTTP proxy [debug] [JSONWP Proxy] Proxying [GET /wd/hub/session/7caca227-e70c-473d-ab9e-6b5c26258dce] to [GET http://127.0.0.1:4728/wd/hub/session/B90ADA83-8975-4189-96C1-70240EBE05D2] with body: {} [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] ========================================== [WinAppDriver] [STDOUT] GET /wd/hub/session/B90ADA83-8975-4189-96C1-70240EBE05D2 HTTP/1.1 [WinAppDriver] [STDOUT] Accept: / [WinAppDriver] [STDOUT] Connection: keep-alive [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] Host: 127.0.0.1:4728 [WinAppDriver] [STDOUT] User-Agent: appium [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] HTTP/1.1 200 OK [WinAppDriver] [STDOUT] Content-Length: 128 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {"sessionId":"B90ADA83-8975-4189-96C1-70240EBE05D2","status":0,"value":{"appTopLevelWindow":"0xA06E0","platformName":"Windows"}} [debug] [JSONWP Proxy] Got response with status 200: "{"sessionId":"B90ADA83-8975-4189-96C1-70240EBE05D2","status":0,"value":{"appTopLevelWindow":"0xA06E0","platformName":"Windows"}}" [JSONWP Proxy] Replacing sessionId B90ADA83-8975-4189-96C1-70240EBE05D2 with 7caca227-e70c-473d-ab9e-6b5c26258dce [HTTP] <-- GET /wd/hub/session/7caca227-e70c-473d-ab9e-6b5c26258dce 200 26 ms - 128 [HTTP] --> POST /wd/hub/session/7caca227-e70c-473d-ab9e-6b5c26258dce/element {"using":"xpath","value":"TitleBar//[starts-with(@value, "HPB8033E")]"} [MJSONWP] Driver proxy active, passing request on via HTTP proxy [debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/7caca227-e70c-473d-ab9e-6b5c26258dce/element] to [POST http://127.0.0.1:4728/wd/hub/session/B90ADA83-8975-4189-96C1-70240EBE05D2/element] with body: {"using":"xpath","value":"TitleBar//[starts-with(@value, "HPB8033E")]"} [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] ========================================== [WinAppDriver] [STDOUT] POST /wd/hub/session/B90ADA83-8975-4189-96C1-70240EBE05D2/element HTTP/1.1 [WinAppDriver] [STDOUT] Accept: / [WinAppDriver] [STDOUT] Connection: keep-alive [WinAppDriver] [STDOUT] Content-Length: 73 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] Host: 127.0.0.1:4728 [WinAppDriver] [STDOUT] User-Agent: appium [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {"using":"xpath","value":"TitleBar//[starts-with(@value, "HPB8033E")]"} [WinAppDriver] [STDOUT] HTTP/1.1 500 Internal Error [WinAppDriver] [STDOUT] Content-Length: 136 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {"status":19,"value":{"error":"XPath Lookup Error","message":"Invalid XPath expression: TitleBar//[starts-with(@value, "HPB8033E")]"}} [MJSONWP] Encountered internal error running command: {"w3cStatus":400,"jsonwp":{"status":19,"value":{"error":"XPath Lookup Error","message":"Invalid XPath expression: TitleBar//[starts-with(@value, "HPB8033E")]"}}} ProxyRequestError: Could not proxy command to remote server. Original error: 500 - {"status":19,"value":{"error":"XPath Lookup Error","message":"Invalid XPath expression: TitleBar//[starts-with(@value, "HPB8033E")]"}} at JWProxy.proxy$ (C:\Users\E2E Lab\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:152:13) at tryCatch (C:\Users\E2E Lab\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40) at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\E2E Lab\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22) at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (C:\Users\E2E Lab\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js💯21) at GeneratorFunctionPrototype.invoke (C:\Users\E2E Lab\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37) at [HTTP] <-- POST /wd/hub/session/7caca227-e70c-473d-ab9e-6b5c26258dce/element 500 371 ms - 199 [HTTP] --> POST /wd/hub/session/7caca227-e70c-473d-ab9e-6b5c26258dce/element {"using":"xpath","value":"TitleBar//[starts-with(@value, "HPB8033E")]"} [MJSONWP] Driver proxy active, passing request on via HTTP proxy [debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/7caca227-e70c-473d-ab9e-6b5c26258dce/element] to [POST http://127.0.0.1:4728/wd/hub/session/B90ADA83-8975-4189-96C1-70240EBE05D2/element] with body: {"using":"xpath","value":"TitleBar//[starts-with(@value, "HPB8033E")]"} [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] ========================================== [WinAppDriver] [STDOUT] POST /wd/hub/session/B90ADA83-8975-4189-96C1-70240EBE05D2/element HTTP/1.1 [WinAppDriver] [STDOUT] Accept: / [WinAppDriver] [STDOUT] Connection: keep-alive [WinAppDriver] [STDOUT] Content-Length: 73 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] Host: 127.0.0.1:4728 [WinAppDriver] [STDOUT] User-Agent: appium [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {"using":"xpath","value":"TitleBar//[starts-with(@value, "HPB8033E")]"} [WinAppDriver] [STDOUT] HTTP/1.1 500 Internal Error [WinAppDriver] [STDOUT] Content-Length: 136 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {"status":19,"value":{"error":"XPath Lookup Error","message":"Invalid XPath expression: TitleBar//[starts-with(@value, "HPB8033E")]"}} [MJSONWP] Encountered internal error running command: {"w3cStatus":400,"jsonwp":{"status":19,"value":{"error":"XPath Lookup Error","message":"Invalid XPath expression: TitleBar//[starts-with(@value, "HPB8033E")]"}}} ProxyRequestError: Could not proxy command to remote server. Original error: 500 - {"status":19,"value":{"error":"XPath Lookup Error","message":"Invalid XPath expression: TitleBar//[starts-with(@value, "HPB8033E")]"}} at JWProxy.proxy$ (C:\Users\E2E Lab\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:152:13) at tryCatch (C:\Users\E2E Lab\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40) at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\E2E Lab\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22) at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (C:\Users\E2E Lab\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js💯21) at GeneratorFunctionPrototype.invoke (C:\Users\E2E Lab\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37) at [HTTP] <-- POST /wd/hub/session/7caca227-e70c-473d-ab9e-6b5c26258dce/element 500 301 ms - 199 [HTTP] --> DELETE /wd/hub/session/12a84140-e463-4765-8bd7-519e30eaa184 {} [debug] [MJSONWP] Calling AppiumDriver.deleteSession() with args: ["12a84140-e463-4765-8bd7-519e30eaa184"] [debug] [BaseDriver] Event 'quitSessionRequested' logged at 1521564050250 (09:40:50 GMT-0700 (Pacific Daylight Time)) [Appium] Removing session 12a84140-e463-4765-8bd7-519e30eaa184 from our master session list [debug] [WinAppDriver] Deleting WinAppDriver session [debug] [WinAppDriver] Deleting WinAppDriver server session

AmitVerma4HP avatar Mar 20 '18 21:03 AmitVerma4HP

Hi @AmitVerma4HP,

There are few issues above that can be broken down as follows:

  1. The XPath expressions you sent are incorrect as the error message precisely described: "Invalid XPath expression: TitleBar//[starts-with(@value, "HPB8033E")]". Below are the corrected XPath queries based on the ones you provided above (notice the placement of // and the capitalization of the attribute). "//TitleBar[starts-with(@Value, "HPB8033E")]")" "//ListItem[starts-with(@Name, "test1 - Notepad")]"

  2. The current XPath lookup does not consider the Value attribute. Hence, even with the proper XPath query, you will not get the TitleBar you are looking for with the current version of WinAppDriver. For the time being, I highly recommend using the Title session property to verify the Printer Queue window title as follows:

// Ensure you have Correct Print Queue opened
Assert.IsTrue(session.Title.StartsWith("HPB8033E"));

Would you give these a try and let us know how it goes?

timotiusmargo avatar Mar 21 '18 00:03 timotiusmargo

@timotiusmargo Sorry for typo in xpath. Both suggested changes worked :-) but I was wondering what properties I should use for constructing xpath expressions (that we supported in WinAppDriver). Are there plans to support other properties/attributes in future like Value etc.?

  1. For title validation below element worked. Assert.IsTrue(session.Title.StartsWith("HPB8033E"));

  2. For queued print job validation - Assert.assertTrue(PrinterQueueSession.findElementByXPath("//ListItem[starts-with(@Name, "test1")]").getText().contains("test1"),"Expected Print Job NOT FOUND in Print Queue");

**its Caps N in the Name for item 2 **

AmitVerma4HP avatar Mar 21 '18 16:03 AmitVerma4HP

Hi @AmitVerma4HP,

Glad to hear those solved your issues. In general we should use element attributes such as AutomationId, Name. ClassName etc to locate or specify the element we are interested in. Currently finding element using XPath are limited to attributes that are populated when you generate the Page Source. But we are looking to make it more versatile in the future.

timotiusmargo avatar Mar 21 '18 20:03 timotiusmargo

Thank you for being very quick in response. Appreciate it. Good to close this issue.

AmitVerma4HP avatar Mar 21 '18 20:03 AmitVerma4HP