isDisplayed not returning false

76 views
Skip to first unread message

Praveen Kumar Natarajan

unread,
Apr 4, 2021, 3:44:08 PM4/4/21
to Selenium Users
My selenium script is not returning 'false' for isDisplayed() method. The script fragment is given below :

WebElement e=driver.findElement(By.linkText("ClassName"));   
boolean b=e.isDisplayed();
System.out.println(b);

I am executing this script on the "ClassName" link web element in the below web page :
<html>
  <head>
    <title>My Title</title>
  </head>
  <body>
    <h1>My First Heading</h1>
    <p>My first paragraph.</p>
    UserName : <input type="text" id="user"> <br>
    DOB : <input type="text" name="dob"> <br>
    Password : <input type="password" id="pid" class="pclass"> <br>
    Gender   : <input type="radio" id="male" name="sex" class="sex">
               <label for="male">Male</label><br>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
               <input type="radio" id="female" name="sex">
               <label for="female">Female</label><br>
    Hobbies  : <input type="checkbox" id="c1">
               <label for="c1">Playing Cricket</label><br>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
           <input type="checkbox" id="c2">
               <label for="c2">Studying</label><br><br><br><br>&nbsp&nbsp&nbsp&nbsp&nbsp     
    <input type="button" value="Submit"> <br>    
    <a style="visibility:hidden" sytle="display:none" class="c1" href="https://www.lambdatest.com/blog/selenium-java-tutorial-class-name-locator-in-selenium/">ClassName</a><br>
    <span>I love you</span> <br>
    <span>You&nbsp;love me</span> <br>
    <span>kids & ladies</span><br>      
    <span>bat&amp;ball</span>
  </body>
</html>

Can someone please help?

Adrian

unread,
Apr 5, 2021, 2:45:44 AM4/5/21
to Selenium Users
Hi,
If you step through your code then does it work?

It maybe that when your code runs, then the link is displayed
And when your code has finished running, then the link has been hidden.
Otherwise I would expected your IsDisplayed() to return false.


Cheers,
Adrian.

Tanvir Hyder Shuvro

unread,
Apr 12, 2021, 1:24:41 AM4/12/21
to Selenium Users
nooo
Reply all
Reply to author
Forward
0 new messages