-1

To select start-date and departure-date for https://www.booking.com/ my code is not giving error but date is not selected.Tried with the actions class but no use.

link:- booking.com

driver.findElement(By.xpath("//input[@id='ss']")).sendKeys("London");
Thread.sleep(5000);
driver.findElement(By.xpath("//span[contains(.,'LondonGreater London, United Kingdom')]")).click();
Thread.sleep(9000);
driver.findElement(By.xpath("//div[@class='xp__dates-inner']")).click();

Actions startdate = new Actions(driver);
WebElement mainMenu = driver.findElement(By.xpath(".//div[@class= 'bui-calendar']//table[@class='bui-calendar__dates']//tr[@class='bui-calendar__row']//td[@data-date='2020-09-27']"));
startdate.moveToElement(mainMenu).click().build().perform();

Thread.sleep(8000);
Actions enddate = new Actions(driver);
WebElement mainMenu1 = driver.findElement(By.xpath(".//div[@class= 'bui-calendar']//table[@class='bui-calendar__dates']//tr[@class='bui-calendar__row']//td[@data-date='2020-09-28']"));
enddate.moveToElement(mainMenu1).click().build().perform();

driver.findElement(By.xpath(".//div[@class='sb-searchbox-submit-col -submit-button ']")).click();
Thread.sleep(6000);
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Madhusudhan R
  • 301
  • 1
  • 5
  • 17

1 Answers1

2

To set Check-in date as Tue 29 Sept and Check-out date as Wed 30 Sept on https://www.booking.com/ you need to induce WebDriverWait for the elementToBeClickable() and you can use the following based Locator Strategies:

driver.get("https://www.booking.com/index.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaGyIAQGYAQm4AQfIAQzYAQHoAQGIAgGoAgO4ArregvsFwAIB0gIkYWZiOGRhYmItNzgxOS00YWFjLWE2YTgtOWQwNTNkNDExYjBl2AIF4AIB;keep_landing=1&sb_price_type=total&");
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[contains(@class, 'xp__dates__checkin')]//span[contains(@class, 'calendar-restructure-sb')]"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='xp-calendar']//table[@class='bui-calendar__dates']//tr//td[@data-date='2020-09-29']"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='xp-calendar']//table[@class='bui-calendar__dates']//tr//td[@data-date='2020-09-30']"))).click();
  • Browser Snapshots:

booking_com_dates

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352