无法关闭广告弹窗。

huangapple go评论135阅读模式
英文:

Not able to close advertisement popup

问题

  1. public class MakeMyTrip {
  2. public static void main(String[] args) {
  3. WebDriverManager.firefoxdriver().setup();
  4. WebDriver driver = new FirefoxDriver();
  5. driver.manage().deleteAllCookies();
  6. driver.manage().window().maximize();
  7. driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
  8. driver.get("https://www.makemytrip.com/");
  9. WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
  10. wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("webklipper-publisher-widget-container-notification-frame")));
  11. WebElement closeButton = driver.findElement(By.xpath("//a[@id='webklipper-publisher-widget-container-notification-close-div']/i"));
  12. closeButton.click();
  13. driver.switchTo().defaultContent();
  14. }
  15. }
英文:

public class MakeMyTrip {

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

}

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.

尝试使用以下代码:

  1. WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
  2. wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("webklipper-publisher-widget-container-notification-frame")));
  3. WebElement closeButton = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@id='webklipper-publisher-widget-container-notification-close-div']/i")));
  4. JavascriptExecutor executor = (JavascriptExecutor) driver;
  5. executor.executeScript("arguments[0].click();", closeButton);
  6. driver.switchTo().defaultContent();
英文:

Use JavascriptExecutor.

Try with this code :-

  1. WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
  2. wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("webklipper-publisher-widget-container-notification-frame")));
  3. WebElement closeButton = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@id='webklipper-publisher-widget-container-notification-close-div']/i")));
  4. JavascriptExecutor executor = (JavascriptExecutor) driver;
  5. executor.executeScript("arguments[0].click();", closeButton);
  6. driver.switchTo().defaultContent();

huangapple
  • 本文由 发表于 2023年4月17日 14:29:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76032240.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定