OpenQA.Selenium.WebDriverException:远程WebDriver服务器对URL的HTTP请求在60秒后超时

时间:2017-04-07 23:46:39

标签: c# selenium selenium-chromedriver

这是我的问题: 我只是尝试运行基本测试,只是为了尝试这一点,并且我一直遇到异常:" OpenQA.Selenium.WebDriverException:对URL 的远程WebDriver服务器的HTTP请求( url here) 60秒后超时"。

我正在使用最新的Selenium,即3.3.0,以及最新的Selenium支持,也是3.3.0。

我已经设置了驱动程序:

    public static class Driver
{
    public static IWebDriver Instance { get; set; }

    public static void Initialize()
    {

        Instance = new ChromeDriver();
    }

    public static void Close()
    {
        Instance.Close();
    }
}

我正在运行一个基本测试,从另一个类登录wordpress帐户,以使测试与逻辑分开:

    [TestMethod]
    public void Test_LogIn()
    {
        WordPressLoginPage.GoTo();
        WordPressLoginPage.LoginAs("*******").WithPassword("*******").Login();
    }

以下是测试所调用的方法:

    public class WordPressLoginPage
{
    private const string LoginUrl = "https://wordpress.com/wp-login.php";

    public static void GoTo()
    {
        Driver.Instance.Navigate().GoToUrl(LoginUrl);
        var wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(5));

        wait.Until(d => d.SwitchTo().ActiveElement().GetAttribute("id") == ("user_login"));
    }

    public static LoginCommmand LoginAs(string userName)
    {
        return new LoginCommmand(userName);
    }
}

public class LoginCommmand
{
    private readonly string _userName;
    private string _password;

    public LoginCommmand(string userName)
    {
        _userName = userName;
    }

    public LoginCommmand WithPassword(string password)
    {
        _password = password;
        return this;
    }

    public void Login()
    {
        var loginInput = Driver.Instance.FindElement(By.Id("user_login"));
        loginInput.SendKeys(_userName);

        var passwordInput = Driver.Instance.FindElement(By.Id("user_pass"));
        passwordInput.SendKeys(_password);

        var loginSubmit = Driver.Instance.FindElement(By.Id("wp-submit"));
        loginSubmit.Submit();

        var wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(65));

        wait.Until(d => d.SwitchTo().ActiveElement().GetAttribute("id") == ("search-component-1"));
    }
}

异常告诉我超时发生在这里:

                loginSubmit.Submit();

我可以看到,在我开始运行页面后,页面仍然可以加载超过两分钟。

我在这里查看过有关同一例外的其他问题,但这些答案似乎都没有帮助。

2 个答案:

答案 0 :(得分:0)

我也是在我的框架中遇到过这个问题,但是在运行单个测试时却没有。当我并行运行多个测试时,这就出现了问题,并且始终使用ChromeDriver进行.Submit()方法。

为了纠正这个问题,我不得不修改我的脚本以点击提交按钮。在此之后,我的脚本运行正常。

为了记录,我使用的是WebDriver和支持包v3.4.0,ChromeDriver v2.29.0和Chrome v58.0.3029.110。

答案 1 :(得分:0)

I also encountered this problem. The issue occurred as a result of password pass through. The test team were all signing into their Virtual machines with the same credentials, Username: X and Password: Y. Similarity, the Virtual machine which stored the application we were testing against also had the same credentials.

However, at a particular point in time one of the developers changed Password from Y to Z. So the authentication for requesting a server response was failing in the background. You effectively need some form of an authentication service for your test project. See below for a good start point:

https://sqa.stackexchange.com/questions/2277/using-selenium-webdriver-with-windows-authentication