尝试处理警报时,Webdriver挂起 [英] Webdriver hangs when trying to handle alerts

查看:67
本文介绍了尝试处理警报时,Webdriver挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此问题中的代码.由于某种原因,无论何时我的测试遇到任何警告,它都不会返回.它击中了这个:

I'm using the code from this question. For some reason any time my test hits anything with an alert it will not return. It hits this:

webDriver.switchTo().alert();

然后永远旋转,永不返回.我希望目前没有警报,但是什么也没发生.

and then just spins forever, never returning. I expect the no alert present exception, but nothing happens.

我还尝试了 this 与没有成功.碰到

I've also tried this with no success. As soon as it hits the

wait.until(ExpectedConditions.alertIsPresent());

它永远旋转.我注意到,如果我手动关闭浏览器,它将跳过它而不会引发异常.我正在使用Ubuntu 14,最新版本的Chrome,最新版本的Webdriver和Chrome驱动程序.我的IDE是IntelliJ IDEA.

it spins forever. I have noticed that if I close the browser manually it will skip past it without throwing an exception. I'm using Ubuntu 14, latest version of Chrome, latest version of Webdriver and Chrome driver. My IDE is IntelliJ IDEA.

我已经找了很长时间,但收效甚微.谁能告诉我如何解决我的问题?

I've looked for quite a while with little success. Can anyone tell me how to fix my problem?

(更新)

我已经玩了很多次,并且发现了一些奇怪的东西.在我的测试中,如果我在代码主体中使用警报功能,则可以正常工作.但是,如果我从代码主体对另一个函数进行调用,然后在该函数中对警报函数进行调用,则它将永远不会从调用中返回.不确定是否有帮助,但我不知道为什么会那么重要.

I've played around with this quite a bit and I've noticed something strange. In my test if I use alert functions in the main body of code it works just fine. However, if I make a call from the main body of code to another function, and then in the function make a call to the alert functions, it will never return from the call. Not sure if that helps but I have no idea why that would matter.

推荐答案

我遇到了同样的问题,以下是我发现的问题:

I had the same issue and the followings are what I've found out:

  1. 在lambda中不能使用switchTo哪个驱动程序实例是参数 例如:

  1. Can't use switchTo within lambda which driver instance is a parameter e.g:

 wait.Until( driver =>  driver.SwitchTo().Alert() );

将导致不稳定的行为(有时有效,有时因为挂起而无法正常工作).我认为这是因为driver.switchTo()更改了驱动程序状态,而lamdba参数应该是不变的.

would cause unstable behavior (sometimes works, sometimes not as it hangs). I think it's because driver.switchTo() changes driver state where lamdba parameter is supposed to be immutable.

不兼容的浏览器驱动程序版本,只需更改驱动程序版本即可解决此问题.

Incompatible browser driver version, Just change driver version would resolve this issue.

这篇关于尝试处理警报时,Webdriver挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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