2016-04-06 17 views
-1

Senaryo: eski ayı ve yeni Ay'ı karşılaştırır ve her ikisi de eşit değilse yeni ayın raporunu karşıdan yükler. Burada Açılır menüde bir seçenek webdriver tarafından okunmuyor

sitesi link: http://www.depreportingservices.state.pa.us/ReportServer/Pages/ReportViewer.aspx?%2fOil_Gas%2fOil_Gas_Well_Historical_Production_Report

O tüm okur ve Ocak 2016 ve yüklemeler rapor ve doğrudan Nov için atlama yerine Aralık rapor indirip okur Tüm seçeneği yok sayar. Statik eski ay i olan bir txt dosyasından alıyorum:

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 

} 

döngü

için
+0

Lütfen eski aydan yeni aya kadar olanları karşılaştır onaylayın –

+0

i statik olarak ayarladım Bir txt dosyası yukarı = Ekim 2015 ay olacak, txt dosyasından dizeyi karşılaştıracağım. Yeniay, seçimdeki "Tümü" den başlıyor. Hepsi! = Ekim 2015, Ocak! = Ok 2015 vs ... – user2762008

cevap

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; 
        } 
       } 

güncelleme geri dönmek zorundadır: Aşağıda

2015 Ekim kodu ise bunu Bu mantık için mantık

// 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

hayır benim sorun Jan okuduktan sonra, Aralık okumalı ama Nov için atlama. Sorun budur. Ben eski ayı Aralık ayında vermek istemiyorum. – user2762008

İlgili konular