简体   繁体   中英

Waiting for an Button to get disabled- Selenium using C#

Hi I am trying to automate tests of my website. Part of it includes clicking on ADD button, entering the information in the text boxes and saving that information. Currently, as soon as my script clicks the ADD button it does not wait and start putting the values in the text box. I tried:

driver.Manage().Timeouts() 

What I am thinking of doing is wait for the ADD button to get disabled and then add the values in the text box. Is there a way to achieve that? The following code is incorrect and gives me an error:

wait.Until(Driver.FindElement(By.Id("addbutton")).Enabled)==false;        

I am assuming your addbutton has an attribute that can be either:

  • enabled
  • disabled

Can you try this approach? Assuming the attribute that toggles between enabled and disabled is named status .

IWebElement element = driver.FindElement(By.Id("addbutton"));
string buttonStatus = element.GetAttribute("status");

Then you can build a loop that waits for its status to change, below is pseudo code:

IWebElement element = driver.FindElement(By.Id("addbutton"));
String buttonStatus = "enabled";
while (buttonStatus!="disabled")||(timeout<5000): (5000 mili seconds)
    buttonStatus = element.GetAttribute("status");
    advance your timer by 100 mS

Your loop will exist if button becomes disabled or 5 seconds has passed.

Try WebDriverWait for this case:

WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, 0, 60));
wait.Until(ExpectedConditions.InvisibilityOfElementLocated(By.Id("addbutton")));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM