更新时间:2023-11-16 15:26:52
This looks like a copy of this question that has already been answered.
我可以向您展示我的工作,这似乎对我来说很有效:
I can show you what I've done, which seems to work well for me:
public static IWebElement WaitForElementToAppear(IWebDriver driver, int waitTime, By waitingElement)
{
IWebElement wait = new WebDriverWait(driver, TimeSpan.FromSeconds(waitTime)).Until(ExpectedConditions.ElementExists(waitingElement));
return wait;
}
这应该等待waitTime时间,直到找到或找不到元素为止.我遇到了很多动态页面无法立即加载所需元素的问题,而WebDriver试图以比页面加载速度更快的速度查找元素,这是我的解决方案.希望对您有帮助!
This should wait waitTime amount of time until either the element is found or not. I've run into a lot of issues with dynamic pages not loading the elements I need right away and the WebDriver trying to find the elements faster than the page can load them, and this is my solution to it. Hope it helps!