I am not able to close the below window on https://www.makemytrip.com/ website:
I tried with alert
, notification
and child browser popup, but nothing had worked out.
Please anyone help on this?
I am not able to close the below window on https://www.makemytrip.com/ website:
I tried with alert
, notification
and child browser popup, but nothing had worked out.
Please anyone help on this?
The object(close button) you should have hit to close the pop up is inside another frame.
So switch to that iframe first and then try to hit the close button. See below the code to switch frame. driver.switchTo().frame("id of the element");
To click on the element X as the desired element is within a <iframe>
so you have to:
Induce WebDriverWait for the desired frameToBeAvailableAndSwitchToIt.
Induce WebDriverWait for the desired elementToBeClickable.
You can use either of the following Locator Strategies:
Using cssSelector:
driver.get("https://www.makemytrip.com/");
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("iframe[title^='notification-frame']")));
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("i.we_close"))).click();
Using xpath:
driver.get("https://www.makemytrip.com/");
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[starts-with(@title, 'notification-frame')]")));
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//i[@class='wewidgeticon we_close']"))).click();
Browser Snapshot:
You can find a couple of relevant discussions in:
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.get("https://www.makemytrip.com/");
driver.manage().window().maximize();
// Switch to the notification iframe
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[starts-with(@title, 'notification-frame')]")));
// Wait for the close button to be clickable
Thread.sleep(12000);
driver.findElement(By.xpath("//i[@class='wewidgeticon we_close']")).click();
// Switch back to the default content
driver.switchTo().defaultContent();