硒RC + c# 如何处理运行新浏览后超时问题?

发布于 2024-10-09 17:10:35 字数 970 浏览 0 评论 0原文

全部 当我学习selenium rc如何使用selenium.click打开新浏览时,我遇到了一个问题。新的浏览器可以正确打开,但是测试工具NUint显示“超时”问题,无论我添加多少时间,它总是出现超时问题。整个代码如下:

[Test]
    public void SelectTest()
    {
        //selenium = new DefaultSelenium("localhost", 4444, "*chrome","http://www.webkey.cn/demo/docs/index2.asp?url=/demo/docs/menuselect/");
       // selenium.Start();
        selenium.Open("http://www.webkey.cn/demo/docs/index2.asp?url=/demo/docs/menuselect/");
        selenium.WaitForPageToLoad("8000");
        selenium.SelectWindow("name=main");
        selenium.Select("city","label=上海市");
        Assert.AreEqual("上海市",selenium.GetSelectedLabel("city"));

        selenium.Select("country","index=1");
        Assert.AreEqual("徐汇区",selenium.GetSelectedLabel("country"));
        selenium.SelectFrame("relative=up");
        selenium.SelectFrame("Header1");
        selenium.Click("link=首页");
        selenium.WaitForPageToLoad("10000");// This code has timed out problem.
}

all
When I learned the selenium rc how to use selenium.click to open a new browse, I have met a problem. The new browse can be opened correctly, but the test tool NUint showed "timed out" problem, whatever I added the time, it always has the timed out problem.The whole codes as following:

[Test]
    public void SelectTest()
    {
        //selenium = new DefaultSelenium("localhost", 4444, "*chrome","http://www.webkey.cn/demo/docs/index2.asp?url=/demo/docs/menuselect/");
       // selenium.Start();
        selenium.Open("http://www.webkey.cn/demo/docs/index2.asp?url=/demo/docs/menuselect/");
        selenium.WaitForPageToLoad("8000");
        selenium.SelectWindow("name=main");
        selenium.Select("city","label=上海市");
        Assert.AreEqual("上海市",selenium.GetSelectedLabel("city"));

        selenium.Select("country","index=1");
        Assert.AreEqual("徐汇区",selenium.GetSelectedLabel("country"));
        selenium.SelectFrame("relative=up");
        selenium.SelectFrame("Header1");
        selenium.Click("link=首页");
        selenium.WaitForPageToLoad("10000");// This code has timed out problem.
}

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

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

发布评论

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

评论(2

蓝色星空 2024-10-16 17:10:35

首先增加默认的硒超时(我记得defaulttimeout = 30000):

selenium.SetTimeout("90000"); // 1.5 minute

第二次增加页面加载的等待时间:

 selenium.WaitForPageToLoad("10000"); // it's only 10 seconds, 
 //increase to 60000 - one minute

编辑:

当时我已经测试了ajax完成的所有点击,并且按顺序使用以下方法重定向后等待页面上的某些元素,因此尝试使用它来等待重定向:

 public static bool WaitForElement(String waitingElement, DefaultSelenium selenium)
        {
            var isElementExists = selenium.IsElementPresent(waitingElement);
            if (!isElementExists)
            {
                Thread.Sleep(50);
                return WaitForElement(waitingElement, selenium);
            }
            else
            {
                return isElementExists;
            }
        }

示例:

 selenium.Open("/sign-up");
 WaitForElement("//input[@name='Invite']", selenium);//Wait...

First increase default selenium timeout(as i remeber defaulttimeout = 30000):

selenium.SetTimeout("90000"); // 1.5 minute

And second increase wait time for page load:

 selenium.WaitForPageToLoad("10000"); // it's only 10 seconds, 
 //increase to 60000 - one minute

EDIT:

At that i've tested all clicks done by ajax and i use followoning methiod in order to wait some element on page after redirect, so try to use this for wait redirect:

 public static bool WaitForElement(String waitingElement, DefaultSelenium selenium)
        {
            var isElementExists = selenium.IsElementPresent(waitingElement);
            if (!isElementExists)
            {
                Thread.Sleep(50);
                return WaitForElement(waitingElement, selenium);
            }
            else
            {
                return isElementExists;
            }
        }

Example:

 selenium.Open("/sign-up");
 WaitForElement("//input[@name='Invite']", selenium);//Wait...
-残月青衣踏尘吟 2024-10-16 17:10:35

尝试

selenium.clickAndWait("link=首页");<br>
selenium.WaitForPageToLoad("60000");

Try

selenium.clickAndWait("link=首页");<br>
selenium.WaitForPageToLoad("60000");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文