Selenium Webdriver C#等待文本出现 [英] Selenium webdriver c# waiting for text to appear
问题描述
我希望实现
wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//div[@id='timeLeft']"), "Time left: 7 seconds"));
c#中的
函数,以等待文本出现.但是,textToBePresentInElementLocated()
仅在Java中可用.是否有一种简单的方法可以在c#中实现这一功能,等待文本出现在页面上?
function in c#, to wait for a text to appear. However, the textToBePresentInElementLocated()
is only available in java. Is there a simple way to achieve this in c# , waiting for text to appear on page?
推荐答案
硒是开源的,因此请看一下它的作用:
Selenium is open source, so take a look at what it does:
You have the power of LINQ however, so it's going to be a little simpler, pseudo:
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.IgnoreExceptionTypes(typeof(StaleReferenceException)); // ignore stale exception issues
wait.Until(d => d.FindElement(By.XPath("//div[@id='timeLeft']")).Text.Contains("Time left: 7 seconds"));
最后一行将等待,直到从d.FindElement(By.XPath("//div[@id='timeLeft']")).Text
返回的文本包含Time left: 7 seconds
.
The last line will wait until the text returned from d.FindElement(By.XPath("//div[@id='timeLeft']")).Text
contains Time left: 7 seconds
.
这篇关于Selenium Webdriver C#等待文本出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!