0

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;        
kotoj
  • 769
  • 1
  • 6
  • 25
Amber O
  • 67
  • 1
  • 9
  • Possible duplicate of [c# webdriver - how can I verify 'disabled' attribute exists for a button](http://stackoverflow.com/questions/25975130/c-sharp-webdriver-how-can-i-verify-disabled-attribute-exists-for-a-button) – JeffC Jun 22 '16 at 21:35
  • What is the error you are getting??? – Saurabh Gaur Jun 23 '16 at 09:35

2 Answers2

0

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.

Yu Zhang
  • 2,037
  • 6
  • 28
  • 42
  • I tried something like this in an if else loop where if loop is doing something when button status is disabled and the else loop handles the not disabled part. while (buttonstatus != "disabled" || timer < 120){ buttonstatus = button.GetAttribute("status");Driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(timer));timer++;}} This throws an error :"Element not found in the cache - perhaps the page has changed since it was looked up". PS: When the button is enabled there is no "status" attribute. – Amber O Jun 22 '16 at 22:09
  • @AmberO, you should not take my code as it is. I do not know how your HTML page looks like. Can you please paste your HTML as well? – Yu Zhang Jun 22 '16 at 22:22
0

Try WebDriverWait for this case:

WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, 0, 60));
wait.Until(ExpectedConditions.InvisibilityOfElementLocated(By.Id("addbutton")));
MartenCatcher
  • 2,713
  • 8
  • 26
  • 39
Thilanka89
  • 31
  • 2