Dear Vamshi,
After clicking on the date box you just need to pick the required date. You do not need the following piece of code since this code is again identifying the date box itself.
Syntax:
driver.findElement(By.id("icon-v2 icon-TUI_Calendar")).click();
According to your code
You have already identified the datebox via "id=when" and clicked on it. If you identify the date box again and click on it for the second time the calendar will disappear. That is the reason your Selenium is unable to pick the date. Moreover ,After identifying the date you need to click on it. So , I would request you to please try the below code.
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Day2
{
public static WebDriver driver= null;
public void invokeBrowser()
{
try
{
System.setProperty("webdriver.chrome.driver","D:\\SeleniumFiles\\Selenium\\Drivers\\chromedriver.exe");
driver= new ChromeDriver();
driver.manage().timeouts().pageLoadTimeout(20,TimeUnit.SECONDS);
driver.get("https://www.tui.co.uk");
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
searchHolidays();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void searchHolidays() throws InterruptedException
{
driver.findElement(By.id("airports")).click();
driver.findElement(By.id("tui_widget_searchpanel_views_CheckBox_1")).click();
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
driver.findElement(By.name("units[]")).sendKeys("spain");
Thread.sleep(5000);
driver.findElement(By.xpath("//input[@id='when']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//div[@class='month-navigator']/following-sibling::div/table/tbody/tr[5]/td[3]/i")).click();;
driver.findElement(By.id("tui_widget_searchpanel_views_SubmitButton_0")).click();
System.out.println("Successfully picked the date.");
}
public static void main(String[] args)
{
Day2 myobj = new Day2();
myobj.invokeBrowser();
}
}
Please try to run the above piece of code. And I would be grateful to you if you reply back on this thread(if this suggestion helped).