Selenium C# ImplicitWait won't wait for element to load

118 Views Asked by At

I have created a custom method to implicitly wait for an element to load, then I use this in a custom click method as so:

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();
}

I then attach this to any element I click on to make sure it always polls the DOM to make sure the element has been loaded, but it doesn't seem to wait for some specific elements to load.

I'm searching for this element as so:

<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']"));

But it always gives off the following exception straight away:

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

I've tried everything to get it to wait for this element to load but I can't seem to figure it out. Weirdly enough if I debug it...it finds the element.

Any help would be greatly appreciated!

0

There are 0 best solutions below