There is an element <label class="CI-MultiplePickerList-column-name-img_logout CI-MultiplePickerList-LAB" style="display: inline;"/> with CSS locator

 .CI-MultiplePickerList-column-name-img_logout.CI-MultiplePickerList-LAB 

This element can have two statuses - when visible to the user and when not visible.

Problem: After clicking on this element, when it has the status displayed: false (that is, when it is not visible to the user), the test crashes and an error appears:

 Element should be visible {.CI-MultiplePickerList-column-name-img_logout.CI-MultiplePickerList-LAB} Element: '<label class="CI-MultiplePickerList-column-name-img_logout CI-MultiplePickerList-LAB" displayed:false></label>' 

I tried to catch the error through exception:

 try { $(By.cssSelector(".CI-MultiplePickerList-column-name-img_logout.CI-MultiplePickerList-LAB")).click(); } catch (ElementNotFound e){ System.out.print("Not logged in profile"); } 

but it did not help.

How can you solve this problem so that the test does not fall when you click on an element with the property displayed: false?

    1 answer 1

    The problem was solved through the getAttrubite method and using the if statement. I check what value the attribute of interest has and if it is invisible (it has the display: none status), then ignore it.

     if($(By.cssSelector(".CI-MultiplePickerList-column-name-img_logout.CI-MultiplePickerList-LAB")).getAttribute("style").equals("display: none;")) { System.out.print("Ignored"); } else{ System.out.print("Else, click it"); $(By.cssSelector(".CI-MultiplePickerList-column-name-img_logout.CI-MultiplePickerList-LAB")).click(); }