2016-09-04 4 views
-1
driver.get("www.exmpale.com"); 
    Thread.sleep(7000); 
    driver.findElement(By.cssSelector(".side-tab.side-generator")).click(); 
    driver.manage().window().maximize(); 
    Thread.sleep(30000); 
    // to find the 5 numbers in list1 and list 2 present in the header and 
    // add them in the list 
    for (int i = 0; i < 7; i++) { 

     numberList1 
       .add(
         driver 
         .findElements(By.cssSelector(".generated-line")) 
         .get(0) 
         .findElements(
           By.cssSelector(".generated-ball.animated.bounceIn>div")      
           ) 

         .get(i).getText() 
         ); 
driver.switchTo().frame(driver.findElement(By.id("lotto-frame-games"))); 

// to find the numbers in the 2 boxes and add them in comparelist1 and 
// comparelist2 
for (int i = 0; i < 7; i++) { 

    compareList1 
      .add(driver 
        .findElements(
          By.cssSelector(".select_num_col_part")) 
        .get(0) 
        .findElements(By.cssSelector(".main_active, .extra_active")) 
        .get(i).getText()); 


//to sort the lists so that lists can be compared easily. 
Collections.sort(numberList1); 
Collections.sort(compareList1); 
System.out.println(numberList1.toString()); 
System.out.println(compareList1.toString()); 

結果:セレンのJava:高低コレクションでソート番号

[13, 16, 27, 34, 5, 7, 7] 
[13, 16, 27, 34, 5, 7, 7] 

私はソートは、私はそれを行うことができますどのように、ローからハイに動作することをしたいですか?

+0

あなたは整数にあなたの文字列を変換し、適切な並べ替えを取得するためにリストにそれを配置する必要があります。 – Grasshopper

+0

@KirillKoganユーザーがあなたの質問に答えた場合は、彼の答えを受け入れてください** [回答を受け入れて:どうしますか?](https://meta.stackexchange.com/questions/5234/how-does-accepting-アンサーワーク))。未回答のものを指定してください、これはStackOverflowの本当に重要な部分です、ありがとうございます。 – Zabuza

答えて

0

あなたはすでにCollections.sort(numberList1);を呼び出していますので、Listをソートしています。

ただし、numberList1にはStringが含まれています。ジェネリックスを使用する場合は、すぐにリストを作成する場所が表示されます。それはこのようなものになりますList<String> numberList1 = new ...

したがって、ソートはlexicographicになります。これは、テキストを並べ替えるかのようになります。だから123の前に来て、1123などのようになります。

リストを整数リスト(List<Integer>)に変更するだけで済みます。あなたのソートはあなたが望むようになります。 StringInteger.parseInt(text)またはnew Integer(text)を使用してIntegerに変換できます。

乾杯

+0

笑私はとても親切、ありがとう –