【发布时间】:2018-12-01 05:28:20
【问题描述】:
我尝试使用下面的代码来检测签到按钮,但我不知道如何选择上图所示的日期。
public class Hotel_Search {
void search(WebDriver driver) {
// find destination WebElement des = driver.findElement(By.name("ss"));
// fill destination des.sendKeys("Ain Sokhna");
// select checkin button 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/button")); Checkinhbutton.click(); //call select date of today method 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/table/thead/tr1/th"))); //find search button 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;
}
}
【问题讨论】:
-
推送您的代码和 HTML(或 URL)。这不是为您编写代码的服务。
标签: selenium selenium-webdriver automated-tests