Wednesday, October 29, 2014

Chapter 22- Check Box Interaction

Check Box Interaction

In this section, we will understand how to interact with Check Box. We can select a Check button option using 'click' method and uncheck using the same 'click' method.
Let us understand, how to interact with check box using - We can also check if the check box is selected/enabled/Visible.
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;

public class webdriverdemo
  public static void main(String[] args) throws InterruptedException
 WebDriver driver = new FirefoxDriver();

 //Puts a Implicit wait, Will wait for 10 seconds before throwing exception
 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

 //Launch website
    // Click on check Box
    System.out.println("The Output of the IsSelected " + driver.findElement("caddoptional")).isSelected());
    System.out.println("The Output of the IsEnabled " + driver.findElement("caddoptional")).isEnabled());
    System.out.println("The Output of the IsDisplayed " + driver.findElement("caddoptional")).isDisplayed());


Upon execution, the Check box is unchecked after the click command(as it was checked by default) and the output of the commands are displayed in the console.

No comments: