WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

WinAppDriver FindElementsByXPath sometimes fails when the singular form succeeds (and vice versa).

Open kfertitta opened this issue 2 years ago • 6 comments

This is something I see a lot, but without any common pattern I'm able to infer. The exact same XPath, when used in the singular FindElementByXPath version works, whereas it returns no results when used in the plural version FindElementsByXPath. In other cases, the opposite is true -- the plural version returns results and the singular version throws a "not found" exception.

Anybody seen this and have any ideas on what may be causing it? It's become tedious to implement the obvious workarounds everywhere.

kfertitta avatar Jan 10 '23 15:01 kfertitta

kfertitta Is it stable if you add some sleep before? FindElementByXPath and FindElementsByXPath have different behavior: FindElementByXPath try to search for an element during the ImplicitWait wait time, but FindElementsByXPath does not wait. Another option to use FluentWait https://www.selenium.dev/documentation/webdriver/waits/

Shakevg avatar Jan 19 '23 16:01 Shakevg

@Shakevg Thank you for the reply. Unfortunately, that does not seem to be the issue, as I have, indeed, tried various waiting scenarios, including the DefaultWait mechanism in WinAppDriver.

For example, the following does not return any results with FindElementsByPath, where as the singular version does:

var wait = DefaultWait(....) { Timeout = TimeSpan.FromSeconds(10) };

var element = wait.Until(s => s.FindElementsByXPath(Locator).FirstOrDefault());

Is nobody else seeing such behavior? Happens a lot to us.

kfertitta avatar Jan 25 '23 15:01 kfertitta

kfertitta I didn't face such issues, maybe it is a bug. You can use FindElementByXPath with DefaultWait for a specific case or try to change XPath as a workaround or try to search parent first, then child items with more simple XPath.

Shakevg avatar Jan 26 '23 07:01 Shakevg

I also have same problem but with FindElementsByName and FindElementsByAccessibilityId. A lot of time. But still don't know how to resolve. Sometime it find, sometime it doesn't find and count = 0;

quynhvan83 avatar Feb 21 '23 10:02 quynhvan83

How about this #1284?

Nativu5 avatar Jul 04 '23 09:07 Nativu5

@Nativu5 , Yes indeed. A quick check reveals that turning off the "ms:experimental-webdriver" option makes FindElementsByXPath work again. Thanks for that.

I guess the question is: what breaks/changes by turning this options off?

kfertitta avatar Jul 04 '23 13:07 kfertitta