【问题标题】:OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL timed out after 60 secondsOpenQA.Selenium.WebDriverException:向远程 WebDriver 服务器请求 URL 的 HTTP 请求在 60 秒后超时
【发布时间】:2017-09-03 10:57:48
【问题描述】:

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

我使用的是最新的 Selenium,即 3.3.0,以及最新的 Selenium Support,也是 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();

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

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

【问题讨论】:

    标签: c# selenium selenium-chromedriver


    【解决方案1】:

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

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

    作为记录,我正在使用 WebDriver 和支持包 v3.4.0、ChromeDriver v2.29.0 和 Chrome v58.0.3029.110。

    【讨论】:

      【解决方案2】:

      我也遇到过这个问题。该问题是由于密码传递而发生的。测试团队都使用相同的凭据登录他们的虚拟机,用户名:X 和密码:Y。类似地,存储我们测试的应用程序的虚拟机也具有相同的凭据。

      但是,在某个特定时间点,一位开发人员将密码从 Y 更改为 Z。因此,请求服务器响应的身份验证在后台失败。您实际上需要为您的测试项目提供某种形式的身份验证服务。请参阅下面的一个好的起点:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-06-28
        • 2018-03-22
        • 2019-02-21
        • 2014-04-14
        • 1970-01-01
        • 2018-11-15
        • 2017-05-06
        • 2023-03-19
        相关资源
        最近更新 更多