FlaUI / FlaUI.WebDriver

MIT License
42 stars 8 forks source link

Find element with xpath failed #107

Closed WeiweiCaiAcpt closed 1 week ago

WeiweiCaiAcpt commented 2 weeks ago

I want to get the Windows desktop ToolBar element in my UI testing. When using FlaUInspect to capture it and the xpath shows in FlaUInspect is "/Pane/ToolBar". image

But I always get "OpenQA.Selenium.NoSuchElementException: No element found with selector 'xpath' and value '//ToolBar'" exception when using driver.FindElementByXPath() method.

Below are the code that we have tried, but non of them are working.

 var toolbar =  driver.FindElementByXPath("/Pane/ToolBar");
 var toolbar =  driver.FindElementByXPath("//Pane/ToolBar");
 var toolbar =  driver.FindElementByXPath("//ToolBar");

Are there anything missing when passing xpath to the method?

bmarroquin commented 2 weeks ago

How are you initializing the driver? Are you using the "Root" app like in https://github.com/FlaUI/FlaUI.WebDriver/issues/59?

WeiweiCaiAcpt commented 2 weeks ago

@bmarroquin Thanks for looking into this issue.

Yes, I use the "Root" app to initialize the driver. I use the same code as this file to initialize the driver: src/FlaUI.WebDriver.UITests/TestUtil/FlaUIAppiumDriverOptions.cs

In https://github.com/FlaUI/FlaUI.WebDriver/issues/59, I see it has been completed on Aug 26. And the FlaUI.WebDriver.exe I used is v0.3.1, which is released on Sep 30. So I think it should be supported to find the desktop element.

aristotelos commented 1 week ago

This was merged in https://github.com/FlaUI/FlaUI.WebDriver/commit/666feb62d05a147439b20976e5c2a2084ef55761 which is tag v0.3.2. Could you try updating?

WeiweiCaiAcpt commented 4 days ago

This was merged in 666feb6 which is tag v0.3.2. Could you try updating?

@aristotelos Thanks for looking into this issue.

I have get the latest version of code and try the FindElement_ByXPath_ReturnsElement() test method in FindElementsTests.cs.

By default, it can find the element when using "//Text" as XPath for the WPF Test Application. And if I tried to get the Taskbar (the parent of Toolbar) with "//Pane" as XPath, the test method can pass.

But if I modify the XPath to "//ToolBar", the test method will failed with error "No element found with selector 'xpath' and value '//ToolBar'". (Also tried with "//Pane/ToolBar" as XPath.)

The same result in my UI Test case.

Background of test scenario: We want to minimize the desktop application window. Then will maximize it from toolbar to restore its window.

aristotelos commented 4 days ago

Sometimes Windows UI Automation seems to not find elements from the root, but only from a parent. Could you try first locating the pane, and then finding elements from the pane?

WeiweiCaiAcpt commented 3 days ago

Sometimes Windows UI Automation seems to not find elements from the root, but only from a parent. Could you try first locating the pane, and then finding elements from the pane?

Yes, I tried with find pane first, then use pane.FindElement(By.Name("")) or pane.FindElement(By.XPath("")) to try find its child element. But unfortunately, both of them are not work.