C# - 如何使用 Watin 检测网站是否返回带有“此页面无法显示"内容的页面? [英] C# - How to detect if website return page with content "This page cannot be displayed "using Watin?

查看:23
本文介绍了C# - 如何使用 Watin 检测网站是否返回带有“此页面无法显示"内容的页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于访问网站的项目.如果网站无法加载,浏览器会显示一个带有文字的页面:无法显示此页面".在这种情况下,我想自动刷新浏览器.程序将如何检测该网站无法加载?.我试过 Ping() 来检查连接,但似乎连接没问题.看看我下面的代码:

I have a project about going to a website. If the website cannot be loaded, and the browser will show a page with text: "This page cannot be displayed" .In this situation, I want to auto refresh the browser. How will the program detect that website can't be loaded? . I've tried Ping() to check the connection, but it seems the connection is fine. Take a look at my below code:

public void exam()
        {
            var ie = new IE();
            ie.GoTo("http://search.yahoo.com");
            ie.WaitForComplete(5);            
            if (ie.ContainsText("This page cannot be displayed"))
            {
                ie.Close();// or ie.Refresh()
            }

        }  

它不起作用.帮助!

推荐答案

你的代码看起来不错,只是从你的等待完成中删除时间确保文本与浏览器中显示的相同.

You code looks fine just remove the time from your wait for complete Make sure the text is same as displayed in the browser.

public void exam()
    {
        var ie = new IE();
        ie.GoTo("http://search.yahoo.com");
        ie.WaitForComplete();            
        if (ie.ContainsText("This page cannot be displayed"))
        {
            ie.Refresh();
        }

    }

这篇关于C# - 如何使用 Watin 检测网站是否返回带有“此页面无法显示"内容的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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