【发布时间】:2014-06-23 17:35:11
【问题描述】:
我看过类似的问题,但没有得到我需要的帮助,我希望这不是重复的......
我希望 selenium 等待 selenium 等待特定值。 或者在某些 javascript 运行时等待。
这是一个例子: 页面对象
class Converter
{
private IWebDriver _webDriver;
[FindsBy(How = How.Id, Using = "tabin")]
public IWebElement HexVaue { get; set; }
[FindsBy(How = How.Id, Using = "resulttxt")]
public IWebElement DecimalValue { get; set; }
[FindsBy(How = How.CssSelector, Using = "#content > form > input[type='button']")]
public IWebElement ConvertButton { get; set; }
public Converter(IWebDriver webDriver)
{
_webDriver = webDriver;
PageFactory.InitElements(_webDriver, this);
}
测试代码:
_driver = new FirefoxDriver();
_driver.Navigate().GoToUrl("http://www.binaryhexconverter.com/hex-to-decimal-converter");
_converter = new Converter(_driver);
_converter.HexVaue.SendKeys("100");
_converter.ConvertButton.Click();
var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(5));
// Assert.AreEqual("256", _converter.DecimalValue.GetAttribute("value")); // Fails
wait.Until(d => _converter.DecimalValue.GetAttribute("value").Equals("256"));
如果我在没有这个 wait.Until 的情况下执行典型的 NUnit 断言,那么测试将失败。这是我在 Selenium 中执行此断言的正确方法吗?
谢谢,达林
【问题讨论】:
标签: c# selenium automation wait specflow