microsoft / WinAppDriver

Windows Application Driver
MIT License
3.66k stars 1.4k forks source link

WinAppDriver hangs when findElement #938

Open tmshft opened 4 years ago

tmshft commented 4 years ago

Now , I am trying to operate Windows .Net form Application by WinAppDriver.

I can create session with remote connection, and I can get some properties such as winHandle,winTitle.

DesiredCapabilities appCap = new DesiredCapabilities();
appCap.setCapability("platformName", "Windows");
appCap.setCapability("deviceName", "WindowsPC");
appCap.setCapability("appTopLevelWindow", {targetWinHandle});
WindowsDriver driver = new WindowsDriver(new URL("http://{my ip}:4723/wd/hub"), appCap);

but when I try to findElementByXPath, the session hangs and no response. I had to shutdown session on cmd console to restart.

driver.findElementByXPath("//*");
# WinAppDriver cmd console

==========================================
POST /wd/hub/session/xxxxxxxxxxxxxxxxxxxxxx/element HTTP/1.1
Accept-Encoding: gzip
Connection: Keep-Alive
Content-Length: 50
Content-Type: application/json; charset=utf-8
Host: x.x.x.x:4723
User-Agent: selenium/3.141.59 (java windows)

{
  "using": "xpath",
  "value": "\u002f\u002f*"
}
... no response ...

I want to know why it hangs, but it may be difficult to solve because the information I've showed is less.

So I wish that WinAppDriver will output some exeption or error log on such case.

Environment

licanhua commented 4 years ago

I'm wondering if it's the problem of Java webdriver. You may be able to help narrow down the problem:

  1. it's //*. here is my output of C# client in WinAppDriver console {"using":"xpath","value":"//*"} and it's "value": "\u002f\u002f*" in your output.
  2. Is your app is ready for testing? You may sleep for some time before find by xpath
  3. try calculator which appid is "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"
NathanZook commented 4 years ago

Per the XPath spec, //* would select every element in the session. I have a hard time conceiving of a situation where this is what you want. If your screen is complex, you might be timing out. The screen for WinAppDriver should inform you if this is the case. Pay attention to the timeout settings when you create the session. Default is 60 seconds.

tmshft commented 4 years ago

@NathanZook , @licanhua Sorry it was bad example. No matter xPath is,(If I tried to using another xPath such as "//Window[@Name=\"{my_app window_name\"]") , then WinAppDriver hangs and no response. And I've tried Windows Calculator sample, and it worked fine.

licanhua commented 4 years ago

It's hard to tell if it's the app or winappdriver problem. winappdriver connected to app by accessibility interface, so it makes WinAppDriver has no response if app itself has no response.

  1. You can check the cpu usage to see who is busy
  2. use visual studio or other debugger. Stack trace and thread information may help you to understand what the process is doing.
  3. other functions(not xpath) which may dump all the elements, for example get page source.
  4. use inspect.exe, narrator, or appium-desktop to inspect the application when problem happens.