【发布时间】:2023-03-18 02:45:01
【问题描述】:
我正在尝试在 C# 中扩展接口 IWebElement 以添加一种新方法来防止 StaleElementReferenceException。
我要添加的方法是一个简单的retryingClick,它会尝试在放弃之前最多点击 WebElement 三次:
public static void retryingClick(this IWebElement element)
{
int attempts = 0;
while (attempts <= 2)
{
try
{
element.Click();
}
catch (StaleElementReferenceException)
{
attempts++;
}
}
}
之所以要添加这个方法,是因为我们的网页大量使用了jQuery,而且很多元素都是动态创建/销毁的,所以为每个WebElement添加保护就成了一个巨大的考验。
那么问题就变成了:我应该如何实现这个方法,以便接口IWebElement可以一直使用它?
谢谢你, 问候。
【问题讨论】:
标签: c# selenium interface extends staleelementreferenceexception