-2

I want to check that an element is not displayed. I have written the following code :

public boolean verifyelementNotDisplayed() {
        try
            {
               if(element("element").isDisplayed())
                   return false;
                   else
                 {
                     logMessage("element not displayed");
                  return true;
                 }
            }
            catch(Exception e)
            {
                return false;
            }

    }

But my test fails.

mazhar islam
  • 5,561
  • 3
  • 20
  • 41
Rishu Saxena
  • 171
  • 1
  • 3
  • 19

2 Answers2

0

The following code worked

        public boolean verifyNoelement() {
            try
            {
               if(element("element").isDisplayed())
               {
               return false;
               }
               return false;
            }
            catch(Exception e)
            {
                 logMessage("No element displayed");
                return true;
            }


        }
Rishu Saxena
  • 171
  • 1
  • 3
  • 19
  • 1
    This will not return false if the method is displayed this will return false everytime because you have a semicolon after your if sentence – Stefan Sprenger Jul 29 '15 at 12:36
0

Try this snippet:

public boolean verifyelementNotDisplayed() {
    try{
       return(!element("element").isDisplayed());
    catch(Exception e){
       return false;
    }
}

And have a look at the is displayed method:

How does Selenium WebDriver's isDisplayed() method work

or:

Where is the implementation for the WebElement.isDisplayed() method in Selenium?

Community
  • 1
  • 1
Stefan Sprenger
  • 1,050
  • 20
  • 42