如何使用 selenium webdriver 关闭 makemytrip.com 中的促销弹出窗口

问题描述 投票:0回答:2

我无法关闭“https://www.makemytrip.com/”网站上的以下窗口:

enter image description here

我尝试使用

alert
notification
和子浏览器弹出窗口,但没有任何效果。

有人帮忙吗?

java selenium-webdriver xpath css-selectors webdriverwait
2个回答
0
投票

你应该点击关闭弹出窗口的对象(关闭按钮)在另一个框架内。

所以先切换到那个 iframe,然后尝试点击关闭按钮。请参阅下面的代码来切换框架。 driver.switchTo().frame("元素的id");


0
投票

要单击元素 X,因为所需的元素在

<iframe>
中,因此您必须:

  • Induce WebDriverWait所需的frameToBeAvailableAndSwitchToIt.

  • Induce WebDriverWait所需的elementToBeClickable.

  • 您可以使用以下任一Locator Strategies

  • 使用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();
    
  • 使用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();
    
  • 浏览器快照:

mmt


参考文献

您可以在以下位置找到一些相关讨论:

© www.soinside.com 2019 - 2024. All rights reserved.