SpiceJet.com网站上的Size()方法给出的结果不正确

时间:2018-06-23 19:01:24

标签: size

我正在尝试使用硒代码来单击特定的复选框。

package com;


import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class KnownCheckBoxes {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        System.setProperty("webdriver.chrome.driver","C:\\SeleniumDrivers\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();

        driver.get("http://www.spicejet.com/");

        driver.manage().window().maximize();
        System.out.println("Window Maximized");
        List<WebElement> count = driver.findElements(By.id("discount-checkbox"));
        System.out.println(count.size());// Always giving count as 1
        int size = count.size();

        for(int i = 0;i<size;i++){
            WebElement discount = count.get(i);
            String s = discount.getText();
            System.out.println(s);// Printing all the check boxes value and not going inside below loop.
            if(s.equalsIgnoreCase(" Indian Armed Forces")){
                System.out.println(discount);
                driver.findElements(By.id("discount-checkbox")).get(i).click();
            }
        }   

    }

}

它给出的输出如下。

最大化窗口 1个 亲朋好友 老年人 印度武装部队 学生 无人陪伴的未成年人

0 个答案:

没有答案