在特定的IWebElement上使用webdriverwait

Jea*_*lea 5 c# selenium webdriver selenium-webdriver

我将selenium webdriverwait方法应用于特定的IWebElement,以便在它们可用时获取此IWebElement的一些子元素.这是我的代码......

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IList<IWebElement> elementsA = wait.Until<IList<IWebElement>>((d) =>
{
     return driver.FindElements(By.XPath("//table[@class='boxVerde']"));
});

foreach (IWebElement iwe in elementsA)
{
      wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
      IList<IWebElement> elementsB = wait.Until<IList<IWebElement>>((d) =>
      {
            return iwe.FindElements(By.XPath("tr/td/div/a"));
            //trying to fetch the anchor tags from the element
       });
}
Run Code Online (Sandbox Code Playgroud)

它一直给我一个错误,说'元素不再附加到DOM'...我认为webdriver等待根本不起作用.我做错了什么人吗?非常感谢提前

bux*_*ter -1

尝试使用这个。它等待元素出现在页面中。

static void ForElementsArePresent(IWebDriver wd, double waitForSeconds, By by)
        {
            try
            {
                WebDriverWait wait = new WebDriverWait(wd, TimeSpan.FromSeconds(waitForSeconds));
                wait.Until(x => (x.FindElements(by).Count > 0));
            }
            catch (WebDriverTimeoutException)
            {
                Console.WriteLine("Waiting for element " + by + " to disappear timed out after " + waitForSeconds + " seconds.");
                throw;
            }                       
        }
Run Code Online (Sandbox Code Playgroud)