SHARE
TWEET

How to deal with checkbox webelement using selenium webdrive

a guest Dec 13th, 2012 41 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.List;
  2.  
  3. import org.openqa.selenium.By;
  4. import org.openqa.selenium.WebDriver;
  5. import org.openqa.selenium.WebElement;
  6. import org.openqa.selenium.firefox.FirefoxDriver;
  7.  
  8.  
  9. public class testCheckox {
  10.  
  11.          
  12.         public static void main(String[] args) {
  13.                 WebDriver myTestDriver = new FirefoxDriver();
  14.                 myTestDriver.get("http://tinyurl.com/yj9jgo");
  15.                
  16.                 List<WebElement> CHECKBOXlist = myTestDriver
  17.                                                                                         .findElements(By
  18.                                                                                         .xpath("//input[@type='CHECKBOX']"));
  19.                
  20.                 for(int i=0;i<CHECKBOXlist.size();i++){
  21.                         System.out.println(CHECKBOXlist.get(i).isSelected());
  22.                 }
  23.  
  24.                
  25.                 for(int i=0;i<CHECKBOXlist.size();i++){
  26.                                 CHECKBOXlist.get(i).click();
  27.                 }
  28.                
  29.                
  30.                 for(int i=0;i<CHECKBOXlist.size();i++){
  31.                         System.out.println(CHECKBOXlist.get(i).isSelected());
  32.                 }
  33.  
  34.         }
  35.  
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top