2016-05-12 13 views
1

これは私がテストしているウェブサイトhttps://www.sydneyairport.com.au/go/car-parking.aspxです。私はほとんど完了していますが、1つの問題で立ち往生しています。selenium webdriverを使用してページ上の日付を選択

私はエントリー日付セクションから「日付と時刻」を選択しましたが、終了日セクションから「日付と時刻」を選択することはできません。

なぜ私はその両方の構造が同じであるにもかかわらず、それができず、エントリー日にそれを行うことができなかったのですが、終了日セクションの変更内容はわかりません。私はセレンを初めて使っていて、誰かが私を助けてくれたら分かります。

これは、入力日付セクションで日付と時刻を選択するために書いたものです。

public void selectDate(WebDriver driver, String fromDate, String toDate) { 


      // selects from date 

      WebElement dateButton = driver.findElement(By.id("period_picker_0")); 
      dateButton.click(); 
      WebElement datepicker = driver.findElement(By.xpath("//div[@class='period_picker_days']/table/tbody/tr/td[1]"));   

      selectDate(datepicker, fromDate); 

      WebElement timeBox = driver.findElement(By.xpath("//div[@class='period_picker_work']/div[2]/input")); 
      timeBox.sendKeys(""); 
      WebElement time = driver 
        .findElement(By.xpath(".//*[@id='timepicker_box_start']/div/div[2]/div/div[1]/div[13]")); 
      time.click(); 


      // Selects to date 

      WebElement dateButton2 = driver.findElement(By.id("period_picker_1")); 
      dateButton2.click(); 
      // dateButton.click(); 
      WebElement datepicker2 = driver 
        .findElement(By.xpath("//div[@class='period_picker_days']/table/tbody/tr/td[2]")); 

      selectDate(datepicker2, toDate); 

      WebElement timeBoxEnd = driver.findElement(By.xpath("//div[@class='period_picker_work']/div[2]/input")); 
      timeBoxEnd.sendKeys(""); 
      WebElement timeEnd = driver 
        .findElement(By.xpath(".//*[@id='timepicker_box_end']/div/div[2]/div/div[1]/div[13]")); 
      timeEnd.click(); 

     } 

public int selectDate(WebElement datepicker, String date) { 
     int ele = 0; 
     List<WebElement> rows_table = datepicker.findElements(By.tagName("tr")); 
     int rows_count = rows_table.size(); 
     for (int row = 0; row < rows_count; row++) { 
      // To locate columns(cells) of that specific row. 
      List<WebElement> Columns_row = rows_table.get(row).findElements(By.tagName("td")); 
      // To calculate no of columns(cells) In that specific row. 
      int columns_count = Columns_row.size(); 
      // Loop will execute till the last cell of that specific row. 
      for (int column = 0; column < columns_count; column++) { 
       // To retrieve text from that specific cell. 
       if (Columns_row.get(column).getText().equals(date)) { 
        ele = column; 
        Columns_row.get(column).click(); 
       } 
      } 
     } 

     return ele; 

    } 

答えて

1

私はこのコードのために多くの仕事をしました。あなたはtrとtdを使用しています。私はそれが必要ないことを示唆しています。

私が使用しているコードを参照してください、私は両方の日付を簡単に選択することができます。あなたはこれを見つけると、さらにクエリのために私に戻って返信するか、このヘルプあなた..

driver.get("https://www.sydneyairport.com.au/go/car-parking.aspx"); 
driver.manage().window().maximize(); 
driver.findElement(By.xpath(".//*[@id='period_picker_0']")).click(); 

Actions a = new Actions(driver); 

WebDriverWait wait = new WebDriverWait(driver,20); 

WebElement entrydate= driver.findElement(By.xpath(".//*[@id='body']/div[1]/div[2]/div[1]/table/tbody/tr/td[1]/table/tbody/tr[5]/td[5]")); 
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='body']/div[1]/div[2]/div[1]/table/tbody/tr/td[1]/table/tbody/tr[5]/td[5]"))); 
a.moveToElement(entrydate).build().perform(); 
Thread.sleep(5000L); 
entrydate.click(); 

WebElement entrytime= driver.findElement(By.xpath(".//*[@id='timepicker_box_start']/div/div[2]/div/div[1]/div[15]")); 
a.moveToElement(entrytime).build().perform(); 
Thread.sleep(5000L); 
entrytime.click(); 

WebElement exitdate= driver.findElement(By.xpath(".//*[@id='body']/div[2]/div[2]/div[1]/table/tbody/tr/td[1]/table/tbody/tr[6]/td[5]")); 
a.moveToElement(exitdate).build().perform(); 
Thread.sleep(5000L); 
exitdate.click(); 

WebElement exittime= driver.findElement(By.xpath(".//*[@id='timepicker_box_end']/div/div[2]/div/div[1]/div[15]")); 
a.moveToElement(exittime).build().perform(); 
Thread.sleep(5000L); 
exittime.click(); 

は返信を行ってください願っています。ハッピーラーニング :-)

+0

私はあなたに非常に感謝しています。私は行動について知っていましたが、私はそれを使うことができませんでした。それは素晴らしい仕事です。助けてくれてありがとう 。 しかし、私はコード内で行う必要がある小さな調整があります。時間リストには、あなたが予約している時刻の時間帯によって決まります。 システム時刻を記録し、日付と時刻の選択を動的に変更するか、スクロールしたり次の使用可能な日付と時刻にスキップするループでコードを実行する必要があります。私は変更を行い、ここに投稿しますが、もう一度お手伝いしてくれてありがとうございます。 – Vinod

+0

ええ、それは素晴らしいだろう..私の答えを好きに感謝:-)ハッピーラーニング.. –

関連する問題