我尝试下面的代码来检测chekin按钮,但我无法确定如何选择日期
公共类Hotel_Search {void search(WebDriver driver){//查找目标WebElement des = driver.findElement(By.name(“ss”)); //填写目的地des.sendKeys(“Ain Sokhna”); //选择签入按钮WebElement Checkinhbutton = driver.findElement(By.xpath(“html / body / div [3] / div / div / div [2] / form / div1 / div [2] / div / div [2] / DIV / DIV / DIV / DIV1 / DIV /按钮“)); Checkinhbutton.click(); //调用今天方法的选择日期SelectDateOfToday(driver.findElement(By.xpath(“html / body / div [3] / div / div / div [2] / form / div1 / div [2] / div / div [ 2] / DIV / DIV / DIV / DIV [2] / DIV [2] / DIV [3] / DIV / DIV / DIV1 /表/ THEAD / TR1 /日“))); //找到搜索按钮WebElement searchbutton = driver.findElement(By.xpath(“html / body / div [3] / div / div / div [2] / form / div1 / div [4] / div [2] / button “)); searchbutton.click(); } public void SelectDateOfToday(WebElement Calender_Xpath){
String today = getCurrentDay();
List<WebElement> columns = Calender_Xpath.findElements(By.tagName("td"));
for (WebElement cell : columns) {
/*
* //If you want to click 18th Date if (cell.getText().equals("18")) {
*/
// Select Today's Date
if (cell.getText().equals(today)) {
cell.click();
break;
}
}
}
private String getCurrentDay() {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate localDate = LocalDate.now();
String date = dtf.format(localDate);
return date;
}
}
1 回答
正如我从你的问题中所理解的那样,你正试图与https://www.booking.com/进行交互 . 为了能够选择日期,您可以尝试以下方法:
输出: