1

I am not able to close the below window on https://www.makemytrip.com/ website:

enter image description here

I tried with alert, notification and child browser popup, but nothing had worked out.

Please anyone help on this?

sound wave
  • 3,191
  • 3
  • 11
  • 29
RajaniMR
  • 21
  • 2
  • This ad is only shown once and then saved in cookies. You can save the cookies in your webdriver and that's it, you take it out the first time. – Juan Melnechuk Feb 19 '23 at 12:38

3 Answers3

1

The object(close button) you should have hit to close the pop up is inside another frame.

enter image description here

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");

Partha
  • 107
  • 9
1

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:

mmt


References

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0
    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();
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Diego Borba Aug 30 '23 at 12:35