gpt4 book ai didi

c# - Selenium、等待元素、页面对象模型、c# 绑定(bind)

转载 作者:行者123 更新时间:2023-11-30 15:35:50 24 4
gpt4 key购买 nike

我们如何等待 IWebElement 被(重新)附加到 DOM?我的场景是这样的,我从 dropdown1 中选择一个值,然后在 dropdown2 上发生点击数据绑定(bind)。所以当我的测试像从 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 准备好进行通信吗?

最佳答案

您好,我知道有点晚了,但我遇到了同样的问题,我通过执行以下操作(使用您的代码)解决了这个问题:

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
wait.Until(By.Id(_pageModel.BtnSave.GetAttribute("id"));

然后它只返回 ID 属性的值,并且不再需要用元素查找来污染您的测试代码。希望能帮助到你。

关于c# - Selenium、等待元素、页面对象模型、c# 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14456392/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com