Share
Go down
michalpelc
Posts : 1
Join date : 2013-08-01

How to mark checkbox in WebDriver

on Thu Aug 01, 2013 4:52 pm
Hi,

At the first I must inform that I'm new in Selenium testing automation Smile ...
I have to test registration functionality of website. 
Unit TC: 
1 open registration xkom website
2 fill all of editable fields
3 mark checkboxes 
4 Click Save button.

As for 1 i 2 my script is working ok, but as for 3 not and I don't know how to perform 4'th step. Please help.

As for checkboxes I've tried many examples - without any success:
1. WebElement oRadioBtn = driver.findElement(By.xpath(".//form[@name='register_form']//input[@name='accept_personal_agr']"));
oRadioBtn.isSelected();
oRadioBtn.click();

2. WebElement oRadioBtn = driver.findElement(By.xpath(".//form[@name='register_form']//input[@name='accept_personal_agr']"));
oRadioBtn.click();
3. WebElement kancheck = driver.findElement(By.name("accept_reg_agr"));
kancheck.click();
System.out.println(kancheck.isSelected());

4. WebElement oRadioBtn = driver.findElement(By.cssSelector("input[name='accept_reg_agr']"));
oRadioBtn.click();

5. WebElement oRadioBtn = driver.findElement(By.xpath("//input[@value='Akceptu']"));
oRadioBtn.click();

6. driver.findElement(By.id("qf_589fee")).click();


7.        List CHECKBOXlist = driver.findElements(By.xpath("//input[@type='CHECKBOX']"));
        for(int i=0;i            System.out.println(CHECKBOXlist.get(i).isSelected());
    }
       
        for(int i=0;i            CHECKBOXlist.get(i).click();
}
        
        for(int i=0;i            System.out.println(CHECKBOXlist.get(i).isSelected());
    }





//REGISTRATION CLASS

package mojpackage;

import org.openqa.selenium.By;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

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

        driver.get("registration xkom site");
              
       WebElement element =  driver.findElement(By.name("user_login"));
        WebElement element1 = driver.findElement(By.name("user_pass1"));
        WebElement element2 = driver.findElement(By.name("user_pass2"));
        WebElement element3 = driver.findElement(By.name("user_name1"));
        WebElement element4 = driver.findElement(By.name("user_name2"));
        WebElement element5 = driver.findElement(By.name("user_email"));
        WebElement element6 = driver.findElement(By.name("user_email_repeat"));
        WebElement element7 = driver.findElement(By.name("user_tel_stac"));

        element.sendKeys("mojlogin");
        element1.sendKeys("mojehaslo");
        element2.sendKeys("mojehaslo");
        element3.sendKeys("mojeimie");
        element4.sendKeys("mojenazwisko");
        element5.sendKeys("mojemailwp.pl");
        element6.sendKeys("mojemailwp.pl");
        element7.sendKeys("597837465");

        element.submit();
        element1.submit();
        element2.submit();
        element3.submit();
        element4.submit();
        element5.submit();
        element6.submit();
        element7.submit();
                
        List CHECKBOXlist = driver.findElements(By.xpath("//input[@type='CHECKBOX']"));
        for(int i=0;i            System.out.println(CHECKBOXlist.get(i).isSelected());
    }
       
        for(int i=0;i            CHECKBOXlist.get(i).click();
}
        
        for(int i=0;i            System.out.println(CHECKBOXlist.get(i).isSelected());
    }
                           
        
            driver.quit();
    }
}
Back to top
Permissions in this forum:
You cannot reply to topics in this forum