isEnabled() method always returns true

shashank sinha :

I want to get the list of Strings for which the check boxes are enabled. But when i use isEnabled(), it always return true even for the disabled check boxes. And in output i get the list of all Strings present in that field.

Below is the code which i have written for it:-

@FindBy(css = "[class *= 'CheckboxTextAligned']")
    private List<WebElement> airportListCheckbox;

public void getEnabledValues() {
        for (WebElement elements : airportListCheckbox) {
            if(elements.isEnabled()==true) {
                for (WebElement airportText : airportListTextName) {
                    airportText.getText();
                    LOG.info(airportText.getText());                
                }
            }       
        }

HTML code is as below:- For Disabled checkboxes:-

<label role="checkbox" aria-label="checkbox" class="inputs__CheckboxTextAligned undefined undefined">
<input type="checkbox" disabled checked>
<span class="inputs__box"><svg width="16px" height="16px" class="inputs__checkIcon" viewBox="0 0 1024 1024">
<path d="434z"></path></svg></span>
<span class="inputs__text">London City</span></label>

for Enabled checkboxes:-

<label role="checkbox" aria-label="checkbox" class="inputs__CheckboxTextAligned undefined undefined">
<input type="checkbox" checked="">
<span class="inputs__box"><svg width="16px" height="16px" class="inputs__checkIcon" viewBox="0 0 1024 1024">
<path d="133z"></path></svg></span>
<span class="inputs__text">London Gatwick</span></label>
Ali CSE :

As your trying to verify the input node is enabled or disabled, isEnabled() checks for the disabled attribute on the element. If the attribute "disabled" is not present, it returns True.

Try the below code:

@FindBy(xpath = "//label[contains(@class, 'CheckboxTextAligned')]/following::input")
private List<WebElement> airportListCheckbox;

public void getEnabledValues() {
for (WebElement elements : airportListCheckbox) {
    if(elements.isEnabled()) {
        for (WebElement airportText : airportListTextName) {
        airportText.getText();
        LOG.info(airportText.getText());                
        }
    }       
}

As you want to check the input node is enabled or not, you need to change your locator a bit because previosly you are try to check the label is enabled/disabled not the input node So you are getting always true.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related