使用Selenium WebDriver检测不到Firefox警报框 [英] Firefox alert box not detected with Selenium WebDriver

查看:477
本文介绍了使用Selenium WebDriver检测不到Firefox警报框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


错误net.serenitybdd.core.Serenity - 没有警报存在(警告:
服务器没有提供任何堆栈跟踪信息)



当我尝试使用此代码检测到警报时,出现此错误:

  alert alertBox = getDriver()。switchTo()。alert(); 

警报弹出确实显示,但是当我通过Selenium执行操作时不完全相同WebDriver和手动。这可能是问题的根源,但我不知道为什么弹出不同。



手动完成时提醒

用Selenium完成的警报



这是调用警报的函数:

 函数confirm_remove(){
return window.confirm(Alert message);

$ / code $ / pre
$ b $ p感谢您的帮助

好的,我找到了一个绕过这个问题的方法,但并没有真正解决它。



我试图插入等待和睡眠像你建议我,但它没有解决问题,警报仍然未被发现。

在我的项目我正在使用一个Test类,它调用我的Page类中的步骤,从我的Page类调用webElements。点击删除按钮的步骤和管理警报的步骤之间,Selenium会丢失警报的处理。所以我重新组合了这两个步骤,Selenium似乎也很好地处理了这个问题。解决方案

更简单一点的解决方案:

  WebDriverWait wait = new WebDriverWait(driver,timeout); 
wait.until(ExpectedConditions.alertIsPresent());

使用WebDriverWait,当页面加载完成时,如警报,popupwindow,模式弹出,隐藏的元素,可见,。

ERROR net.serenitybdd.core.Serenity - No alert is present (WARNING: The server did not provide any stacktrace information)

I get this error when I try to detect an alert with this code:

Alert alertBox = getDriver().switchTo().alert();

The alert popup does show up, but it is not exactly the same when I execute the operation via Selenium WebDriver and manualy. This might be the source of the problem but I don't know why the popup is different.

The alert when done manualy

The alert when done with Selenium

This is the function that calls the alert:

function confirm_remove() {
    return window.confirm("Alert message");
}

Thanks for your help

UPDATE:

Ok I found a way to bypass the problem but not really solve it.

I tried inserting waits and sleep like you suggested me to but it did not solve the problem, the alert was still undetected.

In my project I am using a Test class which calls steps from my Steps class which calls webElements from my Page class. The thing is that between the step which clicks on the "Delete" button and the step that manages the alert, Selenium loses the handling of the alert. So I regrouped those two steps and Selenium seems to handle the alert well.

解决方案

A little more elegant solution :

WebDriverWait wait = new WebDriverWait(driver, timeout);
wait.until(ExpectedConditions.alertIsPresent());

Use the WebDriverWait, every time you have dynamic element that are not present when the page is done loading, like alert, popupwindow, modal popup, hiden element which turn visible,.

这篇关于使用Selenium WebDriver检测不到Firefox警报框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆