How to check and uncheck checkbox with selenium webdriver

Selenium Webdriver checkbox checked n unchecked script

package selenium_examples;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class spicejet_example {

public static void main(String[] args) {

WebDriver driver = new FirefoxDriver();

   driver.get("https://book.spicejet.com/Login.aspx");

   driver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);

   WebElement we = driver.findElement(By.id("AvailabilitySearchInputLoginView_Defense"));

   we.click();

   System.out.println(we.isSelected());

   we.click();

   System.out.println(we.isSelected());


}
}

Output of the above script:-

true
false


Above script checks Checkbox,Indian armed forces personnel in https://book.spicejet.com/ website and unchecks the same checkbox.


isSelected() method verifies whether the element is selected or not.Used for checkboxes, options in a select and radio buttons.
It returns true if the element is currently selected or checked, false otherwise.



No comments:

Related Posts Plugin for WordPress, Blogger...

Fun and Knowledge