3

I have a SAVE button which is active only if I do some changes and then trying to save it. Otherwise its disabled.

This is the html for that button:

<button id="customize-site-save" class="button button--primary" data-ng-class="ButtonController.getCssClasses()" type="button" data-disable-on-call="" data-ng-disabled="PlatformCustomizeSiteController.customizeSiteForm.$pristine" data-ng-click="DisableOnCallController.actionEnabled() && (PlatformCustomizeSiteController.save())" translate-keep-content="true" disabled="disabled">

In this HTML, the disabled tag is only active when the button is disabled. How can I check that disabled is active or not?

This is my x path .//*[@id='customize-site-save'] for the button.

I just want to press the button if there is no disabled tag in the html.

| improve this question | | | | |
0

Can you try if following workaround works for you?

        IWebElement btnEnabled = driver.FindElement(By.Id("customize-site-save"));
        IWebElement buttonDisabled = driver.FindElement(By.CssSelector("button[disabled ='disabled']"));

        bool btnStatus = IsElementPresent(buttonDisabled);
        if (btnStatus== false)
        {
            btnEnabled.Click();
        }


 public bool IsElementPresent(IWebelement element)
    {
        try
        {
          driver.FindElement(element);
            return true;
        }
        catch (NoSuchElementException)
        {
            return false;
        }
    }
| improve this answer | | | | |
  • This is working but I took the idea from the above code and done some changes and implemented the checking in another way. used the below code to check the save button is enabled or disabled. Boolean isPresentbtnEnabled = GlobalVariables.BrowserDriver.findElements(save_button_customize_page).size() > 0; //checking for the enabled save button Boolean isPresentbuttonDisabled = GlobalVariables.BrowserDriver.findElements(save_button_Disabled).size() > 0; //checking for the disabled tag (its false when the button is enabled) after that i used if statement to check true or false – sarath Mar 2 '17 at 20:21
  • Cool! I am glad that approach helped you! – Amol Dakhane Mar 3 '17 at 9:13
0

Use the PageObject Pattern with FindBy Annotation

WebDriverWait webDriverWait = new WebDriverWait(webDriver,timeOutInSeconds,pollingInterval);

FindBy(id = "customize-site-save")
WebElement saveButton;

public saveWhenReady() {
    return webDriverWait.until(ExpectedConditions.visibilityOf(saveButton)).click();
}

If you initialise you waits to your QoS requirements, this will only report a fail only if the button does not appear in time.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.