Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用SeleniumWebDriver是否有任何绕过CookieIFrame的解决方案?_Java_Selenium_Xpath_Iframe_Css Selectors - Fatal编程技术网

Java 使用SeleniumWebDriver是否有任何绕过CookieIFrame的解决方案?

Java 使用SeleniumWebDriver是否有任何绕过CookieIFrame的解决方案?,java,selenium,xpath,iframe,css-selectors,Java,Selenium,Xpath,Iframe,Css Selectors,我无法接受以下网站上嵌入在iframe中的cookie警报: 我尝试了许多方法来解决这个问题,使用驱动程序。switchTo().frame()-方法: 通过使用iframesp_消息的Id\u iframe\u 234327 通过为iframe00插入索引 通过WebElementWebElement=driver.findelelement(by.xpath(“//body/div[6]”/iframe[@src='10])调用iframehttps://cdn.privacy-mgm

我无法接受以下网站上嵌入在iframe中的cookie警报:

我尝试了许多方法来解决这个问题,使用
驱动程序。switchTo().frame()
-方法:

  • 通过使用iframe
    sp_消息的Id\u iframe\u 234327
  • 通过为iframe
    0
    0插入索引
  • 通过WebElement
    WebElement=driver.findelelement(by.xpath(“//body/div[6]”/iframe[@src='10])调用iframehttps://cdn.privacy-mgmt.com/index.html?message_id=234327&consentUUID=b2cb90ea-dfdd-4655-b6b9-89117ff34893&requestUUID=ccb96546-c6b5-44e7-9869-438b32f7ad89&preload_message=true']”);驱动程序.切换到().框架(元素)
不幸的是,他们都没有工作。我总是遇到以下例外情况:

org.openqa.selenium.NoSuchFrameException
在这个具体的例子中,有没有人有正确打开iframe的想法? 我正在Java上使用SeleniumWebDriver 3.141.59,我的测试应该在Mozilla Firefox(80.0.1)和Chromium(85.0.4183.102)上执行。这两款浏览器都是无头推出的。 很高兴您能提供帮助。

单击url中的Alle Akzeptiern,因为所需元素位于
中,因此您必须:

  • 诱导WebDriverWait使所需的框架可用并切换到它

  • 将所需元素的WebDriverWait诱导为可禁用

  • 您可以使用以下任一选项:

    • 使用cssSelector:

    • 使用xpath:

  • 浏览器快照:


参考文献 您可以在以下内容中找到一些相关讨论:

driver.get("https://www.hamburg.de/");
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("iframe[id^='sp_message_iframe']")));
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button[aria-label='Alle akzeptieren']"))).click();
driver.get("https://www.hamburg.de/");
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[starts-with(@id, 'sp_message_iframe')]")));
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@aria-label='Alle akzeptieren']"))).click();