sadasiba panda
sadasiba panda

Reputation: 13

Exception org.openqa.selenium.ElementNotVisibleException: ..element not visible

Trying to select radio button but getting "ElementNotVisibleException:" exception.please refer below code

public class Automatecheckbox {

    public static void main(String[] args) throws InterruptedException {
        // TODO Auto-generated method stub
        System.setProperty("webdriver.chrome.driver", "G:/chromedriver/chromedriver.exe");
        WebDriver driver = new ChromeDriver();

        driver.manage().window().maximize();

        driver.get("http://www.facebook.com");

       WebElement male_radio_button=driver.findElement(By.xpath(".//*[@id='u_0_c']"));


       boolean status=male_radio_button.isDisplayed();

       System.out.println("Male radio button is Displayed >>"+status);

        boolean enabled_status=male_radio_button.isEnabled();

        System.out.println("Male radio button is Enabled >>"+enabled_status);

      boolean selected_status=male_radio_button.isSelected();

        System.out.println("Male radio button is Selected >>"+selected_status);

        Thread.sleep(1000);

        male_radio_button.click();

      boolean selected_status_new=male_radio_button.isSelected();

        System.out.println("Male radio button is Selected >>"+selected_status_new);

    }

}

Upvotes: 0

Views: 8053

Answers (3)

Umang Agarwal
Umang Agarwal

Reputation: 1

Use below code:

driver.findElement(By.xpath("//input[@value='2']")).click();

Upvotes: 0

Alok
Alok

Reputation: 1561

Use the explicit wait (WebDriverWait) to let the WebElement get loaded before performing any execution on it. WebDriverWait object (in this case wait) is initialized just after invoking the ChromeDriver();

WebDriver driver = new ChromeDriver();

/* Initialize the WebDriverWait, with 30 seconds of wait time. */
WebDriverWait wait = new WebDriverWait(driver, 30);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='u_0_c']")));
WebElement male_radio_button=driver.findElement(By.xpath(".//*[@id='u_0_c']"));

Upvotes: 0

Indrapal Singh
Indrapal Singh

Reputation: 364

Try to find element using this code :

WebElement male_radio_button = driver.findElement(By.xpath("//input[@id='u_0_c']"));

Hope it will work!!

Upvotes: 1

Related Questions