在Selenium Webdriver中选择多个带有组合的复选框 [英] selecting multiple check boxes with combinations in selenium webdriver

查看:57
本文介绍了在Selenium Webdriver中选择多个带有组合的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在网页中,有12个复选框可供用户选择.我必须测试复选框的所有可能组合.我必须使用Selenium(Java)来自动化它,每个选择都是有效的.如果我一次选择一个复选框,则从12个复选框中选择一个,我将有12个组合.同样,如果我一次选择两个复选框,则将有96种以上的组合.能否请您帮我弄清楚选择复选框的逻辑.我正在尝试多个for循环,但无法获得所有组合.

In a webpage there are 12 check boxes available for user to select. I have to test the all possible combinations of selection the check boxes. I have to automate the same with Selenium (Java).Each selection is valid.For ex. out of 12 check boxes if I am selection one check box at a time I will have 12 combinations. Similarly if I am selecting two check boxes at a time I will have more than 96 combinations. Can you please help me get the logic to select the check boxes. I am trying with multiple for loops but I am not able to get all combinations.

int boxcount = 12;
int selected = 1;
for (int i = 1; i <= 12; i++) {
    selected = i;
    for (int jcon = 1; jcon <= 4; jcon++) {
        for (int jbox = 1; jbox <= 4; jbox++) {
            if (selected == i & jbox <= jcon) {
                System.out.print("Yes");
                System.out.print(" "); 
                //++selected; 
            } else {
                System.out.print("No");
                System.out.print(" ");
            }
            //selected--; 
        }
        System.out.println("");
    }
}

推荐答案

我使用二进制转换获得了组合

I have got the combinations using the binary conversions

 public static String intToString(int number, int groupSize) {

    StringBuilder result = new StringBuilder();

    for(int i = 11; i >= 0 ; i--) {

        int mask = 1 << i;

        result.append((number & mask) != 0 ? "1" : "0");

        if (i % groupSize == 0)

            result.append('\n');
    }

    result.replace(result.length() - 1, result.length(), "");

    return result.toString();
}


public static List<int[]> get_Combination_list() {

    List<int[]>  combinations_with_int_array = new ArrayList<int[]>();

    for(int i=0;i<=4095;i++) {

        String checkbox_combination =intToString(i,12);

        int[] single_combination = new int[12];

        for (int j=0;j<=11;j++) {

            if(j<11)
            {

                single_combination[j]=Integer.parseInt(checkbox_combination.substring(j, j+1));

            }
            else
            {
                single_combination[j]=Integer.parseInt(checkbox_combination.substring(j));

            }
        }
        combinations_with_int_array.add(single_combination);

    }

    System.out.println("No of combinations : "+combinations_with_int_array.size());

    return combinations_with_int_array;
}

这篇关于在Selenium Webdriver中选择多个带有组合的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆