I am currently working on a code to choose departure date and return journey date, but I am encountering an issue where the return journey date is not being selected. The driver seems to be skipping over the return date selection and proceeding directly to the search button without entering a return date.
public class Callender {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\selenium\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.abhibus.com/");
//to select leaving from
WebElement source =driver.findElement(By.xpath("//*[@id='source']"));
source.clear();
source.sendKeys("Tenal");
Thread.sleep(2000);
source.sendKeys(Keys.ENTER);
//to select destination
WebElement destination =driver.findElement(By.xpath("//*[@id='destination']"));
destination.clear();
destination.sendKeys("Hyderaba");
Thread.sleep(2000);
destination.sendKeys(Keys.ENTER);
WebElement element = driver.findElement(By.xpath("//*[@id=\"datepicker1\"]"));
String journeydate="04-10-2019";
selectJourney(driver,element,journeydate);
Thread.sleep(3000);
WebElement element1 = driver.findElement(By.xpath("//*[@id=\"datepicker2\"]"));
String returndate="06-10-2019";
selectRJourney(driver,element1,returndate);
//to click search button
driver.findElement(By.xpath("//*[@id=\"roundTrip\"]/a")).click();
}
public static void selectRJourney(WebDriver driver, WebElement element1, String returndate) {
JavascriptExecutor je=(JavascriptExecutor)driver;
je.executeScript("arguments[0].setAttribute('value','"+returndate+"');", element1);
// TODO Auto-generated method stub
}
public static void selectJourney(WebDriver driver,WebElement element,String journeydate) {
JavascriptExecutor js= (JavascriptExecutor)driver;
js.executeScript("arguments[0].setAttribute('value','"+journeydate+"');",element);
}
Would appreciate any insights or assistance in identifying what may have gone wrong or what steps I could potentially be overlooking?