Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Getting Incorrect Result From IsEnabled for Radio Button

Speedy993
Speedy993 Posts: 65

I have a pair of radio buttons in an application that I am trying to determine of they are enabled or not. The web element locators are defined like this:
_@FindBy(xpath = "//*[@id=\'frmSubject:noContact\']/tbody/tr/td[1]/div/div[2]/span")
public WebElement frmJudgeDecisionNoContactNo_RB;
@FindBy(xpath = "//*[@id=\'frmSubject:noContact\']/tbody/tr/td[2]/div/div[2]/span")
public WebElement frmJudgeDecisionNoContactYes_RB;
_
The application will disable them in certain conditions and it is working as it should. The issue is that when I use the isEnabled function to check this, it is always coming back as enabled, even when it is not. The application was written using PrimeFaces and the developer thinks that this may be what is causing the problems. He thinks that PrimeFaces is actually using another element that is not visible to store the data.

Here is what he said: ' I think your syntax looks right as far as I can tell. If I was to guess, I bet PrimeFaces is using images for the radio buttons that we see and interact with.
And the radio button that stores the data is hidden, so they probably are not disciplined on setting the enabled property on it since users can’t click it anyways.'

Here is some Selenium script that writes to the console to show what is happening:
if(jReviewPage.frmJDecisionNoContactNo_RB.isEnabled()) {
System.out.println("No Contact No radio button is enabled");
} else {
System.out.println("No Contact No radio button is disabled");
};
if(jReviewPage.frmJDecisionNoContactYes_RB.isEnabled()) {
System.out.println("No Contact Yes radio button is enabled");
} else {
System.out.println("No Contact Yes radio button is disabled");
};

It always shows that the elements are enabled even though when the application is executed they are disabled. Has anyone else had something like this happen? Is there a workaround of some sort? Could it be in how the locators are configured?
Thanks for any assistance you can offer.

Tagged:

Comments

  • benken_parasoft
    benken_parasoft Posts: 1,290 ✭✭✭

    For reference, the javadoc for org.openqa.selenium.WebElement.isEnabled() says this:

    Is the element currently enabled or not? This will generally return true for everything but disabled input elements.

    You show "overflow: hidden". Wouldn't this mean the element is really not visible?
    Perhaps you can check for the element to become invisible?

    import static org.openqa.selenium.support.ui.ExpectedConditions.invisibilityOf;
    ...
    WebDriverWait wait = new WebDriverWait(driver, timeout);
    wait.until(invisibilityOf(frmJDecisionNoContactNo_RB));
    

    Something like this would fail with a Selenium TimeoutException if the condition isn't satisfied within the given timeout.

  • benken_parasoft
    benken_parasoft Posts: 1,290 ✭✭✭

    For reference, ExpectedConditions.(in)visibilityOf actually tests WebElement.isDisplayed(). So, you can also test that directly instead of isEnabled().

  • Speedy993
    Speedy993 Posts: 65

    I used isDisplayed and it returned that the radio buttons are displayed. So the radio buttons say they are enabled and displayed. In this particular test, the two radio buttons are actually disabled (trying to click them will result in a timeout). Speaking of time out, is it possible to dynamically change the timeout period in Selenic? Perhaps I could just try to click the button and have it timeout in a second or two and determine the attribute that way. This is not a real big issue, just rather frustrating and a workaround of some sort would be helpful for future tests.
    Thanks!

  • benken_parasoft
    benken_parasoft Posts: 1,290 ✭✭✭
    edited October 2023

    In this particular test, the two radio buttons are actually disabled (trying to click them will result in a timeout). Speaking of time out, is it possible to dynamically change the timeout period in Selenic?

    In Selenium, a TimeoutException is thrown from the "until" method of a WebDriverWait (or FluentWait). For example, it could happen if you are waiting for an element to become clickable before actually performing the click like "wait.until(elementToBeClickable(element))". Timeouts are configured as shown here: Waiting Strategies

    In contrast, Selenic performs analysis, provides recommendations, and can optionally apply those recommendations automatically as self-healing. Selenic is not what controls timeout behavior in Selenium. However, the Selenic Agent has some configuration options related to self-healing that controls how long to inject or extend the timeout of waits. These are the options "additionalWaitTimePercent " and "minAdditionalWaitTime". More detail: Selenic Agent Options

  • Speedy993
    Speedy993 Posts: 65

    I got this working by using ExpectedConditions to see if the element is clickable and that seems to work well.
    if (TestConstants_eSign.SUBJECT_CASE_TYPE == "Probable Cause") {
    if (ExpectedConditions.elementToBeClickable(eSignPage.frmDecisionNoContactNo_RB).equals(true))
    { System.out.println("ERROR No Contact No radio button should be disabled for Probable Cause case");
    } else { System.out.println("No Contact No radio button is disabled");
    }
    }

  • benken_parasoft
    benken_parasoft Posts: 1,290 ✭✭✭

    Thanks for the update. Offhand, it looks like "elementToBeClickable" tests both isDisplayed() and isEnabled().