>更新:
更新后,我遇到了同样的问题,2.29
它的不一致,这是令人沮丧的部分。
更新结束:
Selenium WebDriver 2.25 版本。浏览器:FF(17.0.1版本)和IE(8)
最烦人/让我发疯的一件事是关于陈旧的元素,我仍然不确定我的测试用例如何一直运行通过; 有时我的测试用例通过了,有时失败了,我正在使用CSSSelector来查找元素,但仍然打开/关闭我的测试用例失败了。
这是我用来查找元素的内容。
这是我在 C# 中的代码
public class WebDriverUtil
{
public static IWebDriver driver = StartBrowser();
private static FirefoxProfile _ffp;
private static IWebDriver _driver;
private static IWebDriver StartBrowser()
{
switch (Common.BrowserSelected)
{
case "ff":
_ffp = new FirefoxProfile();
_ffp.AcceptUntrustedCertificates = true;
_driver = new FirefoxDriver(_ffp);
break;
case "ie":
var options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
_driver = new InternetExplorerDriver(options);
_driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(2));
break;
case "chrome":
//_driver = new ChromeDriver();
break;
}
return _driver;
}
public static IWebElement WaitForElement(By by)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
return wait.Until(drv => drv.FindElement(by));
}
}
public class TestCaseEmployee: WebDriverUtil
{
public static bool EmployeeCase()
{
//....
WaitForElement(By.LinkText("Select All Employee")).Click(); //<<< see error below
}
}
//错误信息:
Test 'M:TestCases.TestCaseEmployee' failed: No response from server for url http://localhost:7056/hub/session/79b742cf-e1dc-4016-bdbb-c2de93cd8fa4/element
OpenQA.Selenium.WebDriverException: No response from server for url http://localhost:7056/hub/session/79b742cf-e1dc-4016-bdbb-c2de93cd8fa4/element
at OpenQA.Selenium.Support.UI.DefaultWait`1.PropagateExceptionIfNotIgnored(Exception e)
at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
我遇到了同样的问题并以这种方式解决:
a) 避免使用"重试"之类的方法来操作 IWebElements,因为这样测试需要很多时间才能运行,是不必要的,并且测试会间歇性地失败。
b) 将 Firefox 版本降级到 5(也许从 FF 3.6 到 6 工作正常,但新版本的 FF 会抛出间歇性异常,例如"集线器/会话没有响应......"
c) 如果你需要在页面上处理通过 Ajax 加载的测试中的元素,请务必提供一个可以停止元素加载的 js 函数,所以你应该在 FindElement 之前从 WebDdriver 调用这个函数并做你想做的事。