我正在尝试使用Selenium WebDriver和PhantomJS编写一个简单的测试,只需登录Reddit,并检查用户名是否等于页面上显示的用户名 . 我在使用ChromeDriver时进行了测试,但使用PhantomJSDriver似乎无法正常工作 . 问题是什么?
这是我的一些代码:
private IWebDriver _driver;
[TestInitialize()]
public void MyTestInitialize()
{
_driver = new PhantomJSDriver();
_driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(100);
}
[TestMethod]
public void PhantomLogin()
{
_driver.Navigate().GoToUrl(
"http://reddit.com"
);
_driver.FindElement(By.Name("user")).SendKeys("{username}");
_driver.FindElement(By.Name("passwd")).SendKeys("{password}");
_driver.FindElement(By.ClassName("btn")).Click();
WebDriverWait wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(30));
wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(
By.ClassName("logout")));
Assert.AreEqual(
"{username}",
_driver.FindElement(By.ClassName("user")).FindElement(By.TagName("a")).GetAttribute("href").Split('/')[4]
);
}
这是我得到的错误:
Message: Test method PhantomDemo.UITests.Test.PhantomLogin threw exception: OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL localhost:6114/session/88d4660-6723-11e7-8858-2fa99172/elements timed out after 60 seconds. ---> System.Net.WebException: The request was aborted: The operation has timed out.
编辑:添加错误和更多代码