Selenium webdriver C# 等待文本出现

Guc*_*mer 1 c# testing selenium webdriver selenium-webdriver

我希望实现

wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//div[@id='timeLeft']"), "Time left: 7 seconds"));
Run Code Online (Sandbox Code Playgroud)

C# 中的函数,等待文本出现。然而,它textToBePresentInElementLocated()仅在 java 中可用。在 C# 中是否有一种简单的方法来实现此目的,等待文本出现在页面上?

小智 5

我能够通过以下方式解决这个问题:

element = driver.FindElement(By.Xpath("//div[@id='timeLeft']")));
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.TextToBePresentInElement(name, "Time left: 7 seconds"));
Run Code Online (Sandbox Code Playgroud)