WebDriverWait 不等待我指定的元素

WebDriverWait is not waiting for the element I specify(WebDriverWait 不等待我指定的元素)
本文介绍了WebDriverWait 不等待我指定的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的代码在尝试从元素中获取文本之前等待元素出现.如果我单步执行允许元素时间出现的代码,它会按预期工作,但如果我在没有断点的情况下运行它,等待似乎会被忽略并引发异常.

I am trying to get my code to wait for an element to appear before trying to get the text from the element. If I step through the code allowing the element time to appear it works as expected, but if I run it without breakpoints the wait appears to be ignored and an exception is raised.

我不明白为什么它被忽略了?

I don't understand why it is being ignored?

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
IWebElement message = wait.Until(driver => driver.FindElement(By.ClassName("block-ui-message")));
string messageText = message.Text;

推荐答案

作为替代方案,您可以为 ElementIsVisible() 引入 WebDriverWait,您可以使用以下 定位器策略:

As an alternative you can induce WebDriverWait for the ElementIsVisible() and you can use the following Locator Strategy:

string messageText = new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until(ExpectedConditions.ElementIsVisible(By.ClassName("block-ui-message"))).GetAttribute("innerHTML");

<小时>

DotNetSeleniumExtras.WaitHelpersnuget 一起使用:

不太清楚你所说的我需要的具体使用指令到底是什么意思.如果您使用的是 SeleniumExtrasWaitHelpers,您可以使用以下解决方案:


Using DotNetSeleniumExtras.WaitHelpers with nuget:

Not that super clear what exactly you meant by specific using directive I need. In-case you are using SeleniumExtras and WaitHelpers you can use the following solution:

string messageText = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.ClassName("block-ui-message"))).GetAttribute("innerHTML");

这篇关于WebDriverWait 不等待我指定的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)