I have successfully launched MMT but after checking fares when I want to click on "Book" button it is giving errors as element not present I have tries xpath, class and id locators but still the same issue also applied the wait statement and tried presently in chrome browser below is the code snippet the code stopped working suddenly earlier it was working fine
package Practice;
import org.junit.Assert;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.Alert;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.time.Duration;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.TimeUnit;
public class Mmt
{
public static void main(String[]args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "/home/gt51022/Downloads/chromedriver_linux64/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://www.makemytrip.com/");
driver.navigate().forward();
driver.manage().window().maximize();
//driver.findElement(By.xpath(" //div[@class=\"fsw_inputBox searchCity inactiveWidget activeWidget\"]")).click();
Thread.sleep(2000);
driver.navigate().forward();
driver.findElement(By.id("fromCity")).sendKeys("IXC");
Thread.sleep(1000);
driver.findElement(By.xpath("//p[@class=\"font12 greyText appendBottom3\"]")).click();
Thread.sleep(1000);
//driver.findElement(By.xpath("//div[@class=\"fsw_inputBox searchToCity inactiveWidget activeWidget\"]")).click();
Thread.sleep(2000);
driver.navigate().forward();
driver.findElement(By.id("toCity")).sendKeys("BOM");
Thread.sleep(2000);
driver.findElement(By.xpath("//p[@class=\"font12 greyText appendBottom3\"]")).click();
// Selecting the date from here //
driver.findElement(By.xpath("/html/body/div[1]/div/div[2]/div/div/div[2]/div[1]/div[3]/div[1]/div/div/div/div[2]/div/div[2]/div[1]/div[3]/div[1]/div[7]")).click();
// Clicking on search button here //
driver.findElement(By.xpath("/html/body/div[1]/div/div[2]/div/div/div[2]/p/a")).click();
//driver.findElement(By.xpath("//*[@id=\"root\"]/div/div[2]/div[2]/div[2]/div/div/div[3]/button")).click();
String parentWindowHandler = driver.getWindowHandle(); // Store your parent window
String subWindowHandler = null;
Set<String> handles = driver.getWindowHandles(); // get all window handles
Iterator<String> iterator = handles.iterator();
while (iterator.hasNext()){
subWindowHandler = iterator.next();
}
driver.switchTo().window(subWindowHandler); // switch to popup window
// Now you are in the popup window, perform necessary actions here
Thread.sleep(4000);
driver.navigate().forward();
driver.findElement(By.xpath("//span[@class=\"bgProperties icon20 overlayCrossIcon\"]")).click();
driver.switchTo().window(parentWindowHandler); // switch back to parent window
// Selecting the flight from here //
Thread.sleep(4000);
driver.findElement(By.xpath(" //span[@class=\"appendRight8\"]")).click();
Thread.sleep(4000);
driver.navigate().forward();
//Actions actions = new Actions(driver);
WebElement Booknow = new WebDriverWait(driver, Duration.ofSeconds(10))
.until(ExpectedConditions.elementToBeClickable(By.id("bookbutton-RKEY:501c58c8-7838-4305-9a7f-68744ae5903d:25_0")));
driver.switchTo().newWindow(WindowType.TAB);
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollTo(0, document.body.scrollHeight)");
driver.findElement(By.className("addTravellerBtn")).click();
driver.findElement(By.className("tvlrInput")).sendKeys("person");
driver.findElement(By.xpath("(//input[@class=\"tvlrInput \"])[2] ")).click();
driver.findElement(By.xpath("(//label)[4]")).click();
driver.findElement(By.className("dropdown__value-container css-1hwfws3")).click();
driver.findElement(By.id("react-select-3-option-1")).click();
driver.findElement(By.xpath("(//input[@class=\"tvlrInput \"])[4]")).sendKeys("1234567890");
driver.findElement(By.xpath("(//div[@class=\"relative\"])[5]")).click();
driver.findElement(By.xpath("(//input[@class=\"tvlrInput \"])[5]")).sendKeys("[email protected]");
}
}
You could try to find the button via the class selector and ignore the randomly generated part of the ID (at least it looks like random), if you haven't already tried that.