简体   繁体   English

如何在Selenium Webdriver中安全处理弹出窗口

[英]How can I handle popup window safely in selenium webdriver

I tried many solutions but none of them worked for me. 我尝试了许多解决方案,但没有一个对我有用。 I have one page where it is opening popup and when I try to perform any operation with that popup , it says element not visible. 我在打开弹出窗口的页面上有一个页面,当我尝试对该弹出窗口执行任何操作时,它说元素不可见。

As per scenario first it takes time to load data so as per below image Popup_1 , And then it shows data as per below image Popup_2. 按照方案,首先需要花费一些时间才能按照下面的图像Popup_1加载数据,然后根据下面的图像Popup_2来显示数据。

I am trying to put condition that do not close popup until I get text "Success:". 我试图提出在收到文本“成功:”之前不会关闭弹出窗口的条件

在此处输入图片说明 在此处输入图片说明

My Code : 我的代码:

 for (String handle : driver.getWindowHandles()) {
    driver.switchTo().window(handle);}


    WebDriverWait waitforEle = new WebDriverWait(driver, 300);
    waitforEle.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//*[@id='divc8fff3cf6a']/div[1]/strong")));              
    driver.findElement(By.xpath("//*[@id='modal']/div[1]/a")).click();          

HTML code of popup : 弹出的HTML代码:

<div class="modal fade in" id="modal" style="display: block;"><div class="modal-header"><a class="close" href="#" data-dismiss="modal">×</a><h3>Delete Listings</h3></div><div class="inner"><div id="divc8fff3cf6a">
    <div class="alert alert-success fade in">
  <button class="close" data-dismiss="alert">×</button>
  <strong>Success:</strong> 1 products have been queued for removal from Amazon.</div>    <div class="modal-footer">
        <a href="#" class="btn btn-small" onclick="location.reload()">Close</a>    </div>
</div><script>
//<![CDATA[
window.customModal = {"formUUID":"#formfbe89bf4a5","modalUUID":"#divc8fff3cf6a"};
if(typeof window.customModal != 'undefined'){
    $(window.customModal["formUUID"]).on("submit", function(e){
        e.preventDefault();
        $.ajax({
            cache: false,
            method: "POST",
            data: $(this).serialize(),
            url: $(this).attr("action"),
            before: function(){
                window.modal.close();
                window.loading.show();
            },
            success: function(data, textStatus){
                window.loading.close();
                window.modal.options["content"] = data;
                window.modal.show();
            }
        });

        return false;
    });

    $(".resubmit").on("click", function(e){
        window.modal.close();
        $(window.app[$(this).data("resubmit")]).trigger("submit");
    });
}
//]]>
</script></div></div>

try this 尝试这个

if(alert.getText().contains("Success:"))

  alert.dismiss();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM