Selenium Webdriver C#等待文本出现 [英] Selenium webdriver c# waiting for text to appear

查看:267
本文介绍了Selenium Webdriver C#等待文本出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望实现

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:

但是,您拥有LINQ的强大功能,因此它将变得更简单,更伪:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆