[英]C# Selenium wait until element display is equal to none
So I'm trying to update a page using selenium which uses javascript, problem is the page its self uses javascript to prompt completion with a element that is always present, however when update isn't in process the style is set to所以我正在尝试使用使用 javascript 的 selenium 更新页面,问题是页面本身使用 javascript 来提示完成一个始终存在的元素,但是当更新不在过程中时,样式设置为
display: none;
How can I use (wait.Until) - Example我如何使用 (wait.Until) - 示例
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("")));
on style changes?关于风格的变化?
So example所以例子
wait.Until(Display: Block; is true);
Html element is, Html 元素是,
<example id="example" style="display: none;" aria-hidden="true">
</example>
To wait for the JavaScript to change the element attribute as style="display: none;"
等待JavaScript将元素属性更改为
style="display: none;"
you have to induce WebDriverWait for the InvisibilityOfElementLocated()
and you can use the following solution:您必须为
InvisibilityOfElementLocated()
引入WebDriverWait ,您可以使用以下解决方案:
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(By.Id("element_id")));
For C# you can follow below steps.对于 C#,您可以按照以下步骤操作。
Download required package from NuGet using command使用命令从 NuGet 下载所需的包
Install-Package DotNetSeleniumExtras.WaitHelpers -Version 3.11.0安装包 DotNetSeleniumExtras.WaitHelpers -Version 3.11.0
For example you wants to choose suggestion from autocomplete textbox for term 'bubai'.例如,您想从自动完成文本框中为术语“bubai”选择建议。 Assume the seggestion is populated using ul and li.
假设使用 ul 和 li 填充 seggestion。
a) To search from dubai send it to textbox using a) 要从迪拜搜索,请使用以下命令将其发送到文本框
var txtSearch = driver.FindElements(By.Id("test_autocomplete")).FirstOrDefault();
txtSearch.SendKeys("dubai");
b) Now make sure ul element is available/visible b) 现在确保 ul 元素可用/可见
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(
SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(By.Id("ul-id")));
c) Then check and click if a suggestion is populated c) 然后检查并单击是否填充了建议
string XpathForLi = "//*[@id='ul-id']/li[1]";
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath(XpathForLi))).Click();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.