2017-08-14 63 views
0

在網頁中有12個複選框供用戶選擇。我必須測試選擇複選框的所有可能的組合。我必須使用Selenium(Java)自動完成相同的操作。每個選擇都是有效的。在12個複選框中,如果我選擇了一個複選框,那麼我將有12個複選框。同樣,如果我一次選擇兩個複選框,我將有超過96個組合。你能幫我拿出邏輯來選擇複選框。我正在嘗試使用多個for循環,但我無法獲得所有組合。在selenium webdriver中選擇多個複選框組合

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(""); 
    } 
} 
+0

節目碼**您試圖** –

+0

我試圖打印是/否爲所選組合的組合避免驗證邏輯。 int boxcount = 12; \t \t int selected = 1; \t \t for(int i = 1; i <= 12; i ++){ \t \t \t selected = i; \t \t \t對(INT jcon = 1; jcon <= 4; jcon ++) \t \t \t { \t \t \t對(INT jbox = 1; jbox <= 4; jbox ++){ \t \t \t \t如果(選擇== i&jbox <= jcon){ \t \t \t \t \t System.out.print(「Yes」); \t \t \t \t \t System.out.print(「」); \t \t \t \t \t // ++ selected; \t \t \t \t} \t \t \t \t別的 \t \t \t \t { \t \t \t \t \t是System.out.print( 「否」); \t \t \t \t \t System.out.print(「」); \t \t \t \t} \t \t \t \t // selected--; \t \t \t} \t \t \t的System.out.println( 「」); \t \t} \t \t}問題 \t} – Jay

+0

代碼,格式正確的,而不是在評論 –

回答

0

我曾與實際網絡元素在嘗試了之前使用二進制轉換

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; 
} 
相關問題