https://www.gcreddy.com/2020/03/software-testing-project.html
Handling a Checkbox using Selenium
Manual Actions on a Check box
Check Displayed status
Check Enabled status
Check Selected status
Click (Check/Uncheck)
Selenium WebDriver Test Steps:
System.setProperty("webdriver.chrome.driver", "D://chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://gcreddy.com/project/create_account.php");
boolean status = driver.findElement(By.name("newsletter")).isDisplayed();
System.out.println("Displayed status is: "+status);//true
status = driver.findElement(By.name("newsletter")).isEnabled();
System.out.println("Enabled status is: "+status);//true
status = driver.findElement(By.name("newsletter")).isSelected();
System.out.println("Intial Selected status is: "+status);//false
driver.findElement(By.name("newsletter")).click();
status = driver.findElement(By.name("newsletter")).isSelected();
System.out.println("Selected status is: "+status);//true
driver.findElement(By.name("newsletter")).click();
status = driver.findElement(By.name("newsletter")).isSelected();
System.out.println("Selected status is: "+status);//false
driver.close();