1

Scenario: On the Screen once I navigate I have to click on the checkbox the first time only... Next time when I run the script the checkbox should not be unchecked.... but Issue: First Time if the checkbox is not selected it gets selected correctly and works as per the requirement but the second time when I run the script the checkbox gets unselected which should not happen Below is my Script: Can someone pls help

WebElement ischecked = driver.findElement(By.xpath("//div[contains(@class,'ui-selectbooleancheckbox')]/following::div[contains(@class,'ui-chkbox-box')][2]"));
    //String ischecked = generatestatisticscheckbox.getAttribute("checked");
    if(!ischecked.isSelected())
    {
        
        DriverUtil.waitUntilPageLoad(driver, 60);
        FormInputsUtil.clickOnCheckBox(driver, AppXPathsConstants.generatehibernatecheckbox);
         
    }
    else if(ischecked.isSelected())
    {
        System.out.println("Navigated to the bottom of the screen");
        //DriverUtil.waitUntilPageLoad(driver, 60);
        System.out.println("Checkbox: " + ischecked + "is already selected");
        
    }
2
  • Show html of those checkboxes – Alexey R. Feb 9 at 14:28
  • <div class="ui-chkbox-box ui-widget ui-corner-all ui-state-default"><span class="ui-chkbox-icon ui-icon ui-icon-blank ui-c"></span></div> – sandy Feb 9 at 14:57
1

The approach you are using works only with native check-boxes (i.e. <input type="checkbox"/>). What you have is a custom element that looks like a check-box and behaves like a check-box but which is not really a check-box from Selenium point of view.

When you have custom check-boxes you need to obtain theirs states via the CSS properties since when you check them, they change their styles to be rendered as checked.

So you need to implement custom method that would check if a checkbox has certain CSS property and if yes, return true, otherwise false.

1
  • thanks Alexey let me try and revert – sandy Feb 9 at 15:29

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.