WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

Validations of elements that should not be displayed

Open matt-stratt opened this issue 6 years ago • 6 comments

In a lot of instances, I need to be able to validate that an element is not there. The only way I see to do this is to check the .Displayed property, but this doesnt really work because it will throw errors around the element not being found which is exactly what I want..

I can obiviously catch this exception, but when we include a maximum wait time with the startup, this means this validation will take that amount of time every time which is just too slow.

Is there a way in WinAppDriver to do something like a .Exists? Where it will just look to see if an element is found in the tree, and if not move on without throwing errors?

matt-stratt avatar May 15 '20 19:05 matt-stratt

I have the same problem - I want to verify that element is NOT displayed. Please help.

pzelazo avatar May 18 '20 13:05 pzelazo

I've achived this by using assertTrue(findElementsByAccessibilityId("elementName").isEmpty()). findElementsByAccessibilityId will return a list so if the list is empty the element is not displayed.

andreii88 avatar May 23 '20 12:05 andreii88

@andonyns actually I do not want to use assert but rather a condition.

The code looks like here: protected static WindowsDriver session; session = new WindowsDriver(new Uri(WindowsApplicationDriverUrl), desiredCapabilities);

if (session.FindElementByName("Wanted element").isEmpty()) { //turn on the option in the system to make "Wanted element" visible for the user }

However you appeach with .isEmpty gives me an error: 'WindowsElement' does not contain a definition for 'isEmpty' and no accessible extension method 'isEmpty' acepting a first argument of type 'WindowsElement' could be found (are you missing a using directive or an assembly reference?)

pzelazo avatar May 24 '20 18:05 pzelazo

Use findElements NOT findElement

andreii88 avatar May 24 '20 18:05 andreii88

@andreii88 looks like it works with additional "s" but not exactly with this method. Instead of isEmpty, IsNullOrEmpty works fine for now. Below version is correct:

if (session.FindElementsByName("Wanted element").IsNullOrEmpty()) { //turn on the option in the system to make "Wanted element" visible for the user }

Thanks @andreii88

pzelazo avatar May 24 '20 20:05 pzelazo

@andreii88 thank you!

matt-stratt avatar May 26 '20 13:05 matt-stratt