简体   繁体   English

Selenium Webdriver在尝试处理警报时挂起

[英]Selenium Webdriver Hangs when Trying to Handle an Alert

I'm using Selenium webdriver java 2.45 and firefox 38 and when trying to handle an alert, it hangs forever.I've looked around for any prior answer to this and all I could find was this . 我正在使用Selenium webdriver java 2.45和firefox 38,当尝试处理警报时,它会永远挂起。我一直在寻找任何对此的先前答案,我所能找到的就是这个 He didn't get any answer and I couldn't comment to reiterate on the question, so please if anyone has encountered this problem your help will be greatly appreciated. 他没有得到任何答案,我也无法对此问题进行评论,因此,如果有人遇到此问题,请您多加帮助。

Unfortunately I cannot attach a code sample or any such thing as it is confidential, but the scenario is as follows: I fill a form that generates an alert upon submission and I use the following code to try to accept the alert: 不幸的是,我无法附加代码示例或任何此类机密信息,但情况如下:我填写了一个表单,该表单在提交后会生成警报,并使用以下代码尝试接受警报:

try {
    (new WebDriverWait(driver_, timeout)).until(ExpectedConditions.alertIsPresent());
} catch (TimeoutException e) {
    throw new NoAlertPresentException();
} catch (Exception e1) {
    throw e1;
}

Alert alert = driver_.switchTo().alert();
String alertText = alert.getText();
if (dismiss)
    alert.dismiss();
else
    alert.accept();

As with the referenced question, this hung forever so I used the Java Robot class to dismiss the alert as follows: 与引用的问题一样,该问题永远挂起,因此我使用Java Robot类来消除警报,如下所示:

try {
    Robot rb;
    rb = new Robot();
    rb.keyPress(KeyEvent.VK_ENTER);
    Thread.sleep(2000);
    rb.keyRelease(KeyEvent.VK_ENTER);
} catch (AWTException | InterruptedException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}

Unfortunately I get an UnhandledAlertException right after, so I don't know what to do. 不幸的是我之后立即收到UnhandledAlertException,所以我不知道该怎么办。 Trying to accept the alert with "driver_.switchTo().alert().accept" right after the Robot code only delayed the Exception generation. 在机器人代码仅延迟异常生成之后,尝试通过“ driver_.switchTo()。alert()。accept”接受警报。

If anyone has a solution, please help. 如果有人有解决方案,请提供帮助。 If anything is unclear or if you have more questions about the situation I'd be glad to answer. 如果有任何不清楚的地方,或者您对这种情况还有其他疑问,我很乐意回答。 I've been on this for 6 hours already. 我已经做了6个小时了。

Extra Information: The default alert management was working a day ago, just before the UI team in the company decided to go asynchronous for their Ajax calls. 额外信息:默认警报管理在一天前开始工作,就在该公司的UI团队决定对其Ajax调用进行异步处理之前。 I don't know if this information is relevant at all but I figured more info is better than not enough info. 我不知道这些信息是否完全相关,但是我认为更多的信息总比没有足够的信息要好。

Firefox version 30 is the best version for selenium webdriver. Firefox 30是硒webdriver的最佳版本。 Downgrade firefox to 30 u will get over the issue 将Firefox降级到30 u可以解决问题

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

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