Trying to click on departure button but it is showing error as the element is not clickable.And can anyone please suggest a way to select the current date without hardcoding.
System.setProperty("webdriver.chrome.driver", "C:\\Users\\rutsahoo\\Documents\\chromedriver.exe" );
WebDriver driver;
String strURL="https://www.makemytrip.com/";
driver= new ChromeDriver();//created object of chrome driver
driver.manage().window().maximize();
driver.get(strURL);
Thread.sleep(4000);
driver.findElement(By.xpath("(//span[@class=\"lbl_input latoBold appendBottom10\"])[1]")).click();
Thread.sleep(4000);
driver.close();
CodePudding user response:
The xpath
you are using isn't highlighting any element in the DOM. First click on the Departure
element and then select from the calendar
.
Imports required for Explicit Waits:
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
driver.get("https://www.makemytrip.com/flights");
WebDriverWait wait = new WebDriverWait(driver,30);
Actions actions1 = new Actions(driver);
// Close the login pop-up
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//p[contains(@class,'login__earn')]")));
WebElement login = driver.findElement(By.xpath("//p[text()='Login or Create Account']"));
actions1.moveToElement(login).click().perform();
// Close the language pop-up
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='langCardClose']"))).click();
// Departure Element
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[@for='departure']"))).click();
// Select the date
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@aria-label='Wed Oct 27 2021']"))).click();