0

public class MakeMyTrip {

public static void main(String[] args) {
    WebDriverManager.firefoxdriver().setup();
    WebDriver driver = new FirefoxDriver();
    driver.manage().deleteAllCookies();
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
    driver.get("https://www.makemytrip.com/");
    
    WebDriverWait wait = new WebDriverWait(driver,  Duration.ofSeconds(20));
    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("webklipper-publisher-widget-container-notification-frame")));
    
    WebElement closeButton = driver.findElement(By.xpath("//a[@id='webklipper-publisher-widget-container-notification-close-div']/i"));
    closeButton.click();
    driver.switchTo().defaultContent();
}

}

In my code, I switched the frame and then tried to close the advertisement. The click is not working and not getting errors in the console also.

Monish Khatri
  • 820
  • 1
  • 7
  • 24
Prince
  • 3
  • 2

1 Answers1

0

Use JavascriptExecutor.

Try with this code :-

    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("webklipper-publisher-widget-container-notification-frame")));

    WebElement closeButton = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@id='webklipper-publisher-widget-container-notification-close-div']/i")));

    JavascriptExecutor executor = (JavascriptExecutor) driver;
    executor.executeScript("arguments[0].click();", closeButton);

    driver.switchTo().defaultContent();
Amit Kumar
  • 16
  • 1
  • 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). – Community Apr 20 '23 at 10:08