【发布时间】:2013-01-05 13:20:07
【问题描述】:
我们如何等待 IWebElement 被(重新)附加到 DOM?我的场景是这样的,我从 dropdown1 中选择一个值,然后单击数据绑定发生在 dropdown2 上。因此,当我的测试类似于从 Dd1 中选择“foo”,然后从 Dd2 中选择“bar”时 -> 我会得到一个异常,因为 Dd2 尚未呈现,所以存在竞争条件。 现在,我知道,我们有 WebDriverWait 类,我们可以像这样使用 Until 方法:
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
wait.Until(By.Id("foo"));
但我真的不想将定位符字符串(“foo”)带入我的测试逻辑,因为它似乎违背了使用页面对象模型的意义。使用 Page 对象模型时,我已经有了 IWebElement 实例
[FindsBy(How = How.Id, Using = "ctl00_MainContentPlaceHolder_actionButtonBarControl_btnSave")]
public IWebElement BtnSave { get; set; }
那么,您知道隐式等待 IWebElement 准备好进行通信的任何方法吗?
【问题讨论】:
-
所以目前我使用它如下,但仍在寻找好的解决方案
-
internal static void WaitForElementToBeReadyAndSelectByText(IWebElement webElement, string s) { for (var i = 0; i
-
您找到了一个好的解决方案吗?我正在为同样的事情苦苦挣扎。
标签: c# selenium webdriver automated-tests selenium-webdriver