英文:
Not able to close advertisement popup
问题
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();
}
}
英文:
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.
答案1
得分: 0
Use JavascriptExecutor.
尝试使用以下代码:
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();
英文:
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();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论