如何在 WatiN 中检测 Javascript 弹出通知?

发布于 2024-08-29 17:04:53 字数 296 浏览 3 评论 0原文

我正在尝试解决一个似乎相当常见的场景。

我有一个网站接受通过两个不同文本字段的输入。如果输入格式错误或无效,我会收到 Javascript 弹出通知。

我不会总是收到一个,但我应该在发生(就像我之前所说的)数据格式错误或找不到搜索结果时收到。

我如何在 WatiN 中检测到这一点?

快速谷歌搜索产生的结果显示了如何点击它们,但我很好奇我是否可以检测到我何时得到一个?

如果有人想知道,我正在使用 WatiN 为我做一些屏幕抓取,而不是集成测试:)

提前致谢!

伊恩

I have a, what seems to be, rather common scenario I'm trying to work through.

I have a site that accepts input through two different text fields. If the input is malformed or invalid, I receive a Javascript pop-up notification.

I will not always receive one, but I should in the event of (like I said earlier) malformed data, or when a search result couldn't be found.

How can I detect this in WatiN?

A quick Google search produced results that show how to click through them, but I'm curious as to whether or not I can detect when I get one?

In case anyone is wondering, I'm using WatiN to do some screen scraping for me, rather than integration testing :)

Thanks in advance!

Ian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谜泪 2024-09-05 17:04:53

这就是我的想法。

在我想出明显的解决方案之前,我多次阅读了这个问题。

我可以用 WatiN 读取 JavaScript 警报框吗?

这是我想出的代码。虽然如果警报没有发生,它确实会强制延迟 3 秒,但它非常适合我的场景。

希望其他人发现这有用..

frame.Button(Find.ByName("go")).ClickNoWait();

System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();

while (stopwatch.Elapsed.TotalMilliseconds < 3000d)
{
    if (alertDialogHandler.Exists())
    {
        // Do whatever I want to do when there is an alert box.
        alertDialogHandler.OKButton.Click();
        break;
    }
}

Here's what I came up with.

I read this question several times before I came up with the obvious solution..

Can I read JavaScript alert box with WatiN?

This is the code I came up with.. While it does force a delay of 3 seconds if the alert doesn't happen, it works perfectly for my scenario.

Hope someone else finds this useful..

frame.Button(Find.ByName("go")).ClickNoWait();

System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();

while (stopwatch.Elapsed.TotalMilliseconds < 3000d)
{
    if (alertDialogHandler.Exists())
    {
        // Do whatever I want to do when there is an alert box.
        alertDialogHandler.OKButton.Click();
        break;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文