R2-D2
R2-D2

Reputation: 143

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

display: none;

How can I use (wait.Until) - Example

wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("")));

on style changes?

So example

wait.Until(Display: Block; is true);

Html element is,

<example id="example" style="display: none;" aria-hidden="true">


</example>

Upvotes: 1

Views: 1251

Answers (2)

Aijaj Hussain Ansari
Aijaj Hussain Ansari

Reputation: 375

For C# you can follow below steps.

  1. Download required package from NuGet using command

    Install-Package DotNetSeleniumExtras.WaitHelpers -Version 3.11.0

  2. For example you wants to choose suggestion from autocomplete textbox for term 'bubai'. Assume the seggestion is populated using ul and li.

a) To search from dubai send it to textbox using

  var txtSearch = driver.FindElements(By.Id("test_autocomplete")).FirstOrDefault();
        txtSearch.SendKeys("dubai");

b) Now make sure ul element is available/visible

 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

   string XpathForLi = "//*[@id='ul-id']/li[1]";

   new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath(XpathForLi))).Click();

Upvotes: 0

undetected Selenium
undetected Selenium

Reputation: 193108

To wait for the JavaScript to change the element attribute as style="display: none;" you have to induce WebDriverWait for the InvisibilityOfElementLocated() and you can use the following solution:

new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(By.Id("element_id")));

Upvotes: 2

Related Questions