This post tells you how to check all the checkboxes present in the page.
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
public class testng_3 {
@Test
public void checkbox() throws Exception
{
FirefoxDriver fd= new FirefoxDriver();
fd.manage().window().maximize();
fd.get(“http://www.flipkart.com/laptops/lenovo~brand/pr?sid=6bo,b5g&otracker=hp_nmenu_sub_electronics_0_Lenovo”);
Thread.sleep(10000);
List checkBoxes = fd.findElements(By.xpath(“//input[@type=’Checkbox’]”));
System.out.println(checkBoxes.size());
for(int i=0; i<checkBoxes.size(); i++){
System.out.println(checkBoxes.get(i).getText());
checkBoxes.get(i).click();
}
fd.close();
}
}
not wrking
LikeLike
tried with your but it is not working on flipkart
My code is :::—
package selone;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class DslrBrandChecboxes {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get(“https://www.flipkart.com/cameras/dslr~type/pr?count=40&otracker=nmenu_sub_Electronics_0_DSLR&sid=jek%2Fp31”);
Thread.sleep(10000);
List checkBoxes = driver.findElements(By.xpath(“//input[@type=’Checkbox’]”));
System.out.println(checkBoxes.size());
}
}
LikeLike