How to Handle Hidden Element In Java Selenium With Example?

How to Handle Hidden Element In Java Selenium With Example?

package com.selenium.mix;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class HandleHiddenElement {
   public static void main(String[] args) throws InterruptedException 
   {
      WebDriver driver=new FirefoxDriver();
      driver.manage().window().maximize();
      driver.get("file:///G:/Testing_Utilities/URL");
      List<WebElement> li=driver.findElements(By.id("male"));
      System.out.println(li.size());
      for(WebElement el:li)
      {
         Integer x=el.getLocation().getX();
         System.out.println("The Location Of x is : -"+x);
         //Integer y=river.findElement(By.id("male")) .getLocation().getY();
         if(x==0)
         {
            System.out.println("Element Is Not Visible Or Hidden");
         }
         else
            el.click();
      }
      Thread.sleep(5000);
      driver.close();
   }
}
Avatar for Softwaretestingo Editorial Board

I love open-source technologies and am very passionate about software development. I like to share my knowledge with others, especially on technology that's why I have given all the examples as simple as possible to understand for beginners. All the code posted on my blog is developed, compiled, and tested in my development environment. If you find any mistakes or bugs, Please drop an email to softwaretestingo.com@gmail.com, or You can join me on Linkedin.

Leave a Comment