0

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);

    }

}
1
  • At which line are you seeing ElementNotVisibleException ? Can you update the Question with the entire error stack trace? Commented Feb 16, 2018 at 8:15

3 Answers 3

1

Try to find element using this code :

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

Hope it will work!!

Sign up to request clarification or add additional context in comments.

Comments

0

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']"));

Comments

0

Use below code:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.