gpt4 book ai didi

java - 如何关闭出现在同一页面上的子弹出窗口

转载 作者:太空宇宙 更新时间:2023-11-04 12:15:35 26 4
gpt4 key购买 nike

我想关闭这个弹出窗口。它不是警报,不在框架中,也不是窗口。我可以关闭它的 Robot 类,但 PM 说在这种情况下使用 Robot 类不是正确的做法。

那么我该如何关闭它呢?

我尝试了很多次,但没有成功。

查看图片:-

https

HTML:

<div id="yui_patched_v3_11_0_1_1473662523684_188" class="page-popup-container-content modal-content yui3-widget-stdmod yui3-widget-content-expanded">
<div id="yui_patched_v3_11_0_1_1473662523684_365" class="yui3-widget-hd modal-header">
<div id="yui_patched_v3_11_0_1_1473662523684_293" class="toolbar-content yui3-widget component toolbar">
<button id="yui_patched_v3_11_0_1_1473662523684_367" class="btn close close-content yui3-widget btn-content btn-focused" type="button">×</button>
</div>
<h3 id="yui_patched_v3_11_0_1_1473662523684_366">Security Tips</h3>
</div>
<div id="yui_patched_v3_11_0_1_1473662523684_344" class="yui3-widget-bd modal-body" style="max-height: 450px; height: 365px;">
<div id="yui_patched_v3_11_0_1_1473662523684_501" class="pop-contain">
<div id="yui_patched_v3_11_0_1_1473662523684_527" style="text-align: center; margin-top: 1em;">
<button id="yui_patched_v3_11_0_1_1473662523684_526" class="lgnBtn btn btnPrimary" type="button" onclick="closepopup1();">Close</button>

尝试使用selenium编写代码:-

WebDriver driver; driver = new FirefoxDriver(); 
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("brcp.infoaxon.com");

String currentHandle = driver.getWindowHandle(); driver.findElement(By.xpath(".//div[1]/a")).click();
Thread.sleep(1000);
Set<String> handles = driver.getWindowHandles();
for (String handle : handles)
{
if (!handle .equals(currentHandle))
{
driver.switchTo().window(handle);
driver.close();
}
driver.switchTo().window(currentHandle);
}

最佳答案

实际上这不是一个新的窗口弹出,它是一个对话框窗口,点击Read More按钮后会弹出,您应该在点击Read More按钮后使用WebDriverWait尝试使用By.cssSelector()找到close按钮,等待该元素可见并可点击,如下所示:-

WebDriverWait wait = new WebDriverWait(driver, 10);

//Click on read more button to open this dialog
wait.until(ExpectedConditions.elementToBeClickable(By.partialLinkText("Read More"))).click();

//Now wait until this dialog close button visible and clickable then click
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.btn.close"))).click();

关于java - 如何关闭出现在同一页面上的子弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39445036/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com