2016-04-06 14 views
-1

シナリオ:古い月と新しい月を比較し、両者が等しくない場合は、新しい月のレポートをダウンロードします。ここ ドロップダウンのオプションがWebdriverによって読み取られない

は、サイトのリンクです: http://www.depreportingservices.state.pa.us/ReportServer/Pages/ReportViewer.aspx?%2fOil_Gas%2fOil_Gas_Well_Historical_Production_Report

それはすべての読み込み、および2016年1月とダウンロードが報告し、直接、11月にスキップの代わりに、12月のレポートをダウンロード読み込みすべてのオプションを無視します。 2015年10月

以下

コードです:

WebElement selectElement = driver.findElement(By.id("ReportViewerControl_ctl04_ctl03_ddValue")); 
      //Getting the count of the values in the drop down list 
       Select listBox = new Select(selectElement); 
       int size1 = listBox.getOptions().size(); 
       //prints the size to the console 
       System.out.println("Total no. of months in the drop down is:"+ size1); 

      System.out.println("The old month is: " + oldMonth); 
      //String newMonth =""; 
      //listBox.selectByIndex(3); 
      String newMonth ; 


       for (int i = 1; i < size1; i++) { 
        WebElement mSelectElement = driver.findElement(By.xpath(".//*[@id='ReportViewerControl_ctl04_ctl03_ddValue']")); 
        List<WebElement> optionsList = mSelectElement.findElements(By.tagName("option")); 
       WebElement element = optionsList.get(i); 
       newMonth = element.getText(); 

       //Message that prints the new month 
       System.out.println("The new month is:"+newMonth); 

      /*Condition to check if the New month is equal to Old month, if it is not equal then proceeds 
      * to download that particular month data or else breaks the loop 
      */ 
       if (!oldMonth.equals("All") & !newMonth.equals("All")) { 
      if (oldMonth.equals(newMonth)) { 
       System.out.println("No new months are available to download"); 
       Wait(10000); 
       driver.close(); 
       break; 
      }//else if (i==1 || (oldMonth.equals(newMonth))) { 
      //else if (i==1 & !(oldMonth.equals(newMonth))) { 
     else if (!(oldMonth.equals(newMonth))) { 
       download report 

} 

それはforループバックに

+0

ここから先月と新月を比較しているか確認してください –

+0

私は右に静的に言った1つのtxtファイルを編集する= octは2015年の月、txtファイルからは文字列を比較します。 newmonthは選択の「すべて」から始まります。すべて!= oct 2015、Jan!= oct 2015など... – user2762008

答えて

0
// your given url 
     driver.get("http://www.depreportingservices.state.pa.us/ReportServer/Pages/ReportViewer.aspx?%2fOil_Gas%2fOil_Gas_Well_Historical_Production_Report"); 
     // take everything inside the dd inside the list 
     List<WebElement> allOptions = driver.findElements(By.xpath("//*[@id='ReportViewerControl_ctl04_ctl03_ddValue']/option")); 
     System.out.println("Size is : " + allOptions.size()); 

     String oldMonth = "Dec 2015 (Unconventional wells)"; // old value that will come form a .txt file 
     for(int i=0;i<allOptions.size();i++){ 
      System.out.println("Values inside the REPORTING PERIOD : " + allOptions.get(i).getText()); 
// now compare old month value with drop down value if matches then perform your action or in your case if not matches then perform your action 
// if(!allOptions.get(i).getText().equals(oldMonth)) 

    if(allOptions.get(i).getText().equals(oldMonth)){ 
     // perform any action 
    allOptions.get(i).click(); // selecting value in the dd 
      driver.findElement(By.id("ReportViewerControl_ctl04_ctl00")).click(); //clicking on view report 
         break; 
        } 
       } 

更新行くことがあります。あなたの場合にiがtxtファイルから取っています静的古い月このロジックに論理

// Condition to check if the New month is equal to Old month, if it is not equal then proceeds 
// to download that particular month data or else breaks the loop 

      if(!oldMonth.equals(newMonth)){ 
       System.out.println(newMonth +"perform your action"); 
       // download particular month data 
      }else{ 
       System.out.println("newMonth matches with oldMonth"); 
       break; 
      } 
+0

私の問題はjanを読んだ後、Decを読むべきですが11月にスキップすることです。それが問題です。私は12月に古い月を与えたくありません。 – user2762008

関連する問題