Validations of elements that should not be displayed
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?
I have the same problem - I want to verify that element is NOT displayed. Please help.
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.
@andonyns actually I do not want to use assert but rather a condition.
The code looks like here:
protected static WindowsDriver
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?)
Use findElements NOT findElement
@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
@andreii88 thank you!