I am automating a feature where I need to click on the radio button but after many attempts, it didn't work. So I checked with isDisplayed, isEnabled and isSelected.

Upon execution it was found that the isDisplayed and isEnabled are false and isSelected is true. So, in this case, how can I perform click on this radio button.

Automation using: Cucumber + Selenium with java.

Below is the detailed information:

Screenshot: Screenshot of the element

HTML Code:

    <solvup-radio-type _ngcontent-c7="" _nghost-c9=""><div _ngcontent-c9="" class="ng-invalid ng-dirty ng-touched">
        <solvup-label _ngcontent-c9="" _nghost-c33=""><label _ngcontent-c33="" class="control-label">
        Which Remedy are you authorising? <!----><span _ngcontent-c33="" class="required-mark">*</span> 
    <solvup-tooltip _ngcontent-c33="" _nghost-c36=""><!---->
      <!----><div _ngcontent-c9="" class="radio">
          <label _ngcontent-c9="" class="">
              <input _ngcontent-c9="" type="radio" id="replace_refund_override_radio" class="ng-valid ng-dirty ng-touched">
      </div><div _ngcontent-c9="" class="radio">
          <label _ngcontent-c9="" class="">
              <input _ngcontent-c9="" type="radio" id="replace_refund_override_radio" class="ng-valid ng-dirty ng-touched">
    <solvup-hint-text _ngcontent-c9="" _nghost-c34=""><!----><p _ngcontent-c34="" class="help-block"></p>
    <solvup-validation-messages _ngcontent-c9="" _nghost-c35=""><!----><div _ngcontent-c35="" class="">

Selenium code:

    @Given("^User Overriddes Refund$")
    public void user_Overriddes_Refund() throws Throwable {
        driver.findElement(By.xpath("//div[@class ='radio']/following-sibling::div/label/input")).isDisplayed();
        driver.findElement(By.xpath("//div[@class ='radio']/following-sibling::div/label/input")).isSelected();
        driver.findElement(By.xpath("//div[@class ='radio']/following-sibling::div/label/input")).isEnabled();
        //new WebDriverWait(driver, 50).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class ='radio']/following-sibling::div/label/input")));
        WebElement radio = driver.findElement(By.xpath("//div[@class ='radio']/following-sibling::div/label/input"));
        Actions ob = new Actions(driver);
        Action action = ob.build();
        //List<WebElement> li = driver.findElements(By.id("replace_refund_override_radio"));

Does anyone have any suggestion on this?

2 Answers 2


//div[@class ='radio']/following-sibling::div/label/input

Above locator used in your script will locate 2 radio buttons, You can use the following locators to uniquely select refund/replace:

refund: //input[contains(@text, 'Refund')]

replace: //input[contains(@text, 'Replace')]


On observing the html code you pasted it seems that locator you are using in not unique i.e id="replace_refund_override_radio". ID is same for 02 elements and also all the locators you created are pointing to first element i.e Replace not to Refund. Reason for that if there are multiple elements having same locator then locator engine will pick only first element. To navigate to next element you need to modify the locator like:

List<WebElement> li = driver.findElements(By.id("replace_refund_override_radio"));

//div[@class ='radio']/following-sibling::div/label/input[2]

You may be ask or wondering if you clicked on Replace checkbox it should work. But as what i think Refund and Replace are toggle based check boxes. You cannot deselect any checkbox until you select another. Please check if the software testing services you are automating are working with this. If not please add more info to the question.

  • I have already tried this approach of using List and the using the index value to click. The issue here is when i use isDisplayed and isEnables it comes false. Commented Nov 26, 2018 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.