HomeSelenium

Selenium Interview Question 6 – How can you find whether an element is displayed on the screen using Selenium WebDriver?

Selenium Interview Question 6 – How can you find whether an element is displayed on the screen using Selenium WebDriver?

<<Previous Question       <<1500 Plus Interview Questions>>       Next Question>>

How can you find whether an element is displayed on the screen using Selenium WebDriver?

Watch the answer for this Selenium Interview Question in a detailed manner in the below youtube video:

Note: Don’t forget to subscribe to my Youtube channel.

Notes used for explanation in this Youtube video are provided after the video:

Notes used in the above Youtube Video:

There are two ways to find out whether an element is displayed on the page screen or not.

First way using Selenium WebDriver command – isDisplayed()

  • > Direct way
  • > Reusable method for the direct way

public static boolean isElementPresent(By by) {
              
               try {
                     
                      driver.findElement(by ).isDisplayed();
                     
                      return true ;
                     
              } catch(Exception e ) {
                     
                      return false ;
                     
              }
              
              
       }

Second way using Selenium WebDriver command – findElements()

  • > driver.findElements().size()

public static boolean isElementPresentMethod(String x) {
              
               if(driver .findElements(By.xpath (x )).size()>0) {
                     
                      return true ;
                     
              } else {
                     
                      return false ;
                     
              }
       
       }

Next Steps:

  • > For more Selenium Interview Questions and answers, continue to the next post (Click on Next Post link below)
  • > Check complete Selenium Interview Questions list here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning 🙂

About Me > Arun Motoori

<<Previous Question       <<1500 Plus Interview Questions>>       Next Question>>

On a mission to contribute to the Software Testing Community in all possible ways.

If you like this article, share it on LinkedIn using the below button:

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *