これは私がテストしているウェブサイト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;
}
私はあなたに非常に感謝しています。私は行動について知っていましたが、私はそれを使うことができませんでした。それは素晴らしい仕事です。助けてくれてありがとう 。 しかし、私はコード内で行う必要がある小さな調整があります。時間リストには、あなたが予約している時刻の時間帯によって決まります。 システム時刻を記録し、日付と時刻の選択を動的に変更するか、スクロールしたり次の使用可能な日付と時刻にスキップするループでコードを実行する必要があります。私は変更を行い、ここに投稿しますが、もう一度お手伝いしてくれてありがとうございます。 – Vinod
ええ、それは素晴らしいだろう..私の答えを好きに感謝:-)ハッピーラーニング.. –