Selenium C#ImplicitWait不会等待元素加载

时间:2018-11-21 15:36:51

标签: c# selenium implicitwait

我创建了一个自定义方法来隐式等待元素加载,然后在自定义click方法中使用它,如下所示:

public static void WeElementToBeClickable(this IWebElement element, int sec = 10)
{
    var wait = new WebDriverWait(Driver.Browser(), TimeSpan.FromSeconds(sec));
    wait.Until(ExpectedConditions.ElementToBeClickable(element));     
}

public static void WeClick(this IWebElement element, int sec = 10)
{
    element.WeElementToBeClickable();
    element.Click();
}

然后将其附加到我单击的任何元素上,以确保它始终轮询DOM以确保已加载该元素,但它似乎并不等待某些特定的元素加载。

我正在这样搜索该元素:

<span class="button add fr" onclick="GoToHash('/ContractorCommon/Contractor/ContractorAdd', null, 'Contractor'); "><span class="icon-add"></span> Contractor</span>

public IWebElement AddContractorIcon => Driver.FindElement(By.XPath("//span[@class='button add fr']"));

但是它总是立即发出以下异常:

OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: {"method":"xpath","selector":"//span[@class='button add fr']"}

我已经尽一切努力让它等待该元素加载,但是我似乎无法弄清楚。如果我调试它就很奇怪了……它找到了元素。

任何帮助将不胜感激!

0 个答案:

没有答案