microsoft / WinAppDriver

Windows Application Driver
MIT License
3.7k stars 1.41k forks source link

Windows Element identified by inspector but not by WinAppDriver #1698

Open anupekshajain opened 2 years ago

anupekshajain commented 2 years ago

I am trying to automate our desktop application using Winappdriver [with Java]. There is a ultra menubar in the application whose attributes are identified by inspector tool, UI recorder and even accessibility insights. But when I try to locate it in my script it fails saying that no element found with the given parameters.

One thing that I observed is that even though the inspector identifies the attributes of this ultra menu bar and its submenu, it is not displayed in the tree structure under Root in the left pane.

I need help on how to locate such elements as my scripts are struck due to this.

I tried creating a desktop session and searched the element in the Root node after waiting for 10-40 seconds but it is not listed in the Page source itself.

Tree55Topz commented 2 years ago

You need to include screenshots of what you are picking up in the inspector and your code used to identify the element if you'd like help with this issue.

anupekshajain commented 2 years ago

Accessibilty Insight Inspector tool UIRecorder

Here are the snaps of Inspector, UI Recorder & Accessibility Insights tool, The hierarchy displayed in UI Recorder & Accessibility Insights is not displayed in the Inspector tool. And the properties displayed in the inspector with that also it is unable to locate element.

Below is the code snippet I am using -

WindowsDriver DesktopSession = null; //Click on Actions Menu and hover down on SubmenuItems act.moveByOffset(0, 130).build().perform(); DesiredCapabilities capNew = new DesiredCapabilities(); capNew.setCapability("app", "Root"); try { DesktopSession = new WindowsDriver(new URL("http://127.0.0.1:4723"), capNew); WindowsElement MainMenu = DesktopSession.findElementByName("Actions-0") WindowsElement subMenu = MainMenu.findElement(By.name("Quick Letters")); submenu.click(); } catch(Exception e) { log.info(e.getMessage()); }

And this is the exception I am getting -

2022-04-01 11:19:30 [main] INFO :: exceptionAn element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: 'BLR-763F163-L', ip: '192.168.1.103', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.1' Driver info: io.appium.java_client.windows.WindowsDriver Capabilities {app: Root, javascriptEnabled: true, platform: WINDOWS, platformName: Windows} Session ID: 2D2BC898-7726-440C-835A-18E74F17F363 *** Element info: {Using=name, value=Actions-0} Hopefully this will make my question clear.

aliahmadbutt4 commented 2 years ago

I had the similar issue. But I used Robotframework Zoomba library to write my test cases. So here is the advice: Since there are two windows first one is root(i.e "Practie Management System...") and the second one is with your menu list. So first try to switch to the second window(i.e. "Client Details: J00006 - Jennifer Jones") and then you will find the element which you are trying to access. Later, you have to switch back to the main window.

anupekshajain commented 2 years ago

Thanks for the reply @aliahmadbutt4 . But we already were on the clients window where we were unable to locate the element, so is the Root [Desktop session] is coming into picture, but that too did not work yet.

liljohnak commented 2 years ago

Most of the time inspect.exe is what you can see with WinAppDriver. https://github.com/microsoft/WinAppDriver/issues/755

paul-foreflight commented 2 years ago

I'd say stop trying to find the second element from within the first element, just do an xpath query DesktopSession.FindElement(By.XPATH('//MenuItem[@Name="QuickLetters"]')).click() I've found that as much as you think appium would like to be fed the first element and then search within that element, it just doesn't work out that way. I've sped up and eliminated a lot of random failures looking in tables this way. Menu Items should be similar