selenium webdriver – On selecting the radio button how to get the text of the selected radio button where the text is in the next column

On selecting the radio button how to get the text of the selected radio button where the text is in the next column

I randomly select the radio button and then i need to Store the selected Radio button’s Vessel Name

Below is the Code:

public   String checkselectedplanningVesselname()
    {
        String rowOne = "";
            
            List<WebElement> radiobuttonoptions =driver.findElements(By.xpath("//table[contains(@class,'mat-table cdk-table')]//following::mat-radio-button[contains(@id,'mat-radio')]"));
             for (int i=0;i<radiobuttonoptions.size();i++)
            if(driver.findElement(By.xpath("//table[contains(@class,'mat-table cdk-table')]//following::mat-radio-button[contains(@id,'mat-radio')]")).isSelected())
            {
             
            
             rowOne = radiobuttonoptions.get(i).getText(); = 
             System.out.println("Print the Selected VesselName:"+ rowOne);
           break;
         
        }
        return rowOne;
    }

Below is the HTML of the table :

HTML:

    <tbody role="rowgroup">
       <tr _ngcontent-epp-c110="" role="row" mat-row="" class="mat-row cdk-row ng-star-inserted">
          <td _ngcontent-epp-c110="" role="gridcell" mat-cell="" class="mat-cell cdk-cell cdk-column-radio mat-column-radio ng-star-inserted">
             <span _ngcontent-epp-c110="" class="ng-star-inserted">
                <!---->
                <mat-radio-button _ngcontent-epp-c110="" color="primary" class="mat-radio-button mat-primary ng-star-inserted" id="mat-radio-1"><label class="mat-radio-label" for="mat-radio-1-input"><span class="mat-radio-container"><span class="mat-radio-outer-circle"></span><span class="mat-radio-inner-circle"></span><input type="radio" class="mat-radio-input cdk-visually-hidden" id="mat-radio-1-input" tabindex="0" value="8252"><span mat-ripple="" class="mat-ripple mat-radio-ripple mat-focus-indicator"><span class="mat-ripple-element mat-radio-persistent-ripple"></span></span></span><span class="mat-radio-label-content"><span style="display: none;">&nbsp;</span></span></label></mat-radio-button>
                <!----><!---->
             </span>
             <!----><span _ngcontent-epp-c110="" class="ng-star-inserted"></span><!---->
          </td>
          <td _ngcontent-epp-c110="" role="gridcell" mat-cell="" class="mat-cell cdk-cell cdk-column-vesselName mat-column-vesselName ng-star-inserted">
             <!----><span _ngcontent-epp-c110="" class="ng-star-inserted">TESTVESSELTECHM1</span><!---->
          </td>
          <td _ngcontent-epp-c110="" role="gridcell" mat-cell="" class="mat-cell cdk-cell cdk-column-vettingStatus mat-column-vettingStatus ng-star-inserted">
             <!----><span _ngcontent-epp-c110="" class="ng-star-inserted">GREEN</span><!---->
          </td>
          <td _ngcontent-epp-c110="" role="gridcell" mat-cell="" class="mat-cell cdk-cell cdk-column-imoNumber mat-column-imoNumber ng-star-inserted">
             <!----><span _ngcontent-epp-c110="" class="ng-star-inserted">00121</span><!---->
          </td>
          <td _ngcontent-epp-c110="" role="gridcell" mat-cell="" class="mat-cell cdk-cell cdk-column-vouageId mat-column-vouageId ng-star-inserted">
             <!----><span _ngcontent-epp-c110="" class="ng-star-inserted">TBD</span><!---->
          </td>
          <td _ngcontent-epp-c110="" role="gridcell" mat-cell="" class="mat-cell cdk-cell cdk-column-lastValidityDate mat-column-lastValidityDate ng-star-inserted">
             <!----><span _ngcontent-epp-c110="" class="ng-star-inserted">2035-10-05</span><!---->
          </td>
          <!---->
       </tr>
       <tr _ngcontent-epp-c110="" role="row" mat-row="" class="mat-row cdk-row ng-star-inserted">
          <td _ngcontent-epp-c110="" role="gridcell" mat-cell="" class="mat-cell cdk-cell cdk-column-radio mat-column-radio ng-star-inserted">
             <span _ngcontent-epp-c110="" class="ng-star-inserted">
                <!---->
                <mat-radio-button _ngcontent-epp-c110="" color="primary" class="mat-radio-button mat-primary ng-star-inserted mat-radio-checked" id="mat-radio-2"><label class="mat-radio-label" for="mat-radio-2-input"><span class="mat-radio-container"><span class="mat-radio-outer-circle"></span><span class="mat-radio-inner-circle"></span><input type="radio" class="mat-radio-input cdk-visually-hidden" id="mat-radio-2-input" tabindex="0" value="8253"><span mat-ripple="" class="mat-ripple mat-radio-ripple mat-focus-indicator"><span class="mat-ripple-element mat-radio-persistent-ripple"></span></span></span><span class="mat-radio-label-content"><span style="display: none;">&nbsp;</span></span></label></mat-radio-button>
                <!----><!---->
             </span>
             <!----><span _ngcontent-epp-c110="" class="ng-star-inserted"></span><!---->
          </td>
          <td _ngcontent-epp-c110="" role="gridcell" mat-cell="" class="mat-cell cdk-cell cdk-column-vesselName mat-column-vesselName ng-star-inserted">
             <!----><span _ngcontent-epp-c110="" class="ng-star-inserted">TESTVESSELTECHM2</span><!---->
          </td>
          <td _ngcontent-epp-c110="" role="gridcell" mat-cell="" class="mat-cell cdk-cell cdk-column-vettingStatus mat-column-vettingStatus ng-star-inserted">
             <!----><span _ngcontent-epp-c110="" class="ng-star-inserted">GREEN</span><!---->
          </td>
          <td _ngcontent-epp-c110="" role="gridcell" mat-cell="" class="mat-cell cdk-cell cdk-column-imoNumber mat-column-imoNumber ng-star-inserted">
             <!----><span _ngcontent-epp-c110="" class="ng-star-inserted">00122</span><!---->
          </td>
          <td _ngcontent-epp-c110="" role="gridcell" mat-cell="" class="mat-cell cdk-cell cdk-column-vouageId mat-column-vouageId ng-star-inserted">
             <!----><span _ngcontent-epp-c110="" class="ng-star-inserted">TBD</span><!---->
          </td>
          <td _ngcontent-epp-c110="" role="gridcell" mat-cell="" class="mat-cell cdk-cell cdk-column-lastValidityDate mat-column-lastValidityDate ng-star-inserted">
             <!----><span _ngcontent-epp-c110="" class="ng-star-inserted">2035-10-15</span><!---->
          </td>
          <!---->
       </tr>
       <tr _ngcontent-epp-c110="" role="row" mat-row="" class="mat-row cdk-row ng-star-inserted">
          <td _ngcontent-epp-c110="" role="gridcell" mat-cell="" class="mat-cell cdk-cell cdk-column-radio mat-column-radio ng-star-inserted">
             <span _ngcontent-epp-c110="" class="ng-star-inserted">
                <!---->
                <mat-radio-button _ngcontent-epp-c110="" color="primary" class="mat-radio-button mat-primary ng-star-inserted" id="mat-radio-3"><label class="mat-radio-label" for="mat-radio-3-input"><span class="mat-radio-container"><span class="mat-radio-outer-circle"></span><span class="mat-radio-inner-circle"></span><input type="radio" class="mat-radio-input cdk-visually-hidden" id="mat-radio-3-input" tabindex="0" value="8301"><span mat-ripple="" class="mat-ripple mat-radio-ripple mat-focus-indicator"><span class="mat-ripple-element mat-radio-persistent-ripple"></span></span></span><span class="mat-radio-label-content"><span style="display: none;">&nbsp;</span></span></label></mat-radio-button>
                <!----><!---->
             </span>
             <!----><span _ngcontent-epp-c110="" class="ng-star-inserted"></span><!---->
          </td>
          <td _ngcontent-epp-c110="" role="gridcell" mat-cell="" class="mat-cell cdk-cell cdk-column-vesselName mat-column-vesselName ng-star-inserted">
             <!----><span _ngcontent-epp-c110="" class="ng-star-inserted">TESTVESSELTECHM1</span><!---->
          </td>
          <td _ngcontent-epp-c110="" role="gridcell" mat-cell="" class="mat-cell cdk-cell cdk-column-vettingStatus mat-column-vettingStatus ng-star-inserted">
             <!----><span _ngcontent-epp-c110="" class="ng-star-inserted">GREEN</span><!---->
          </td>
          <td _ngcontent-epp-c110="" role="gridcell" mat-cell="" class="mat-cell cdk-cell cdk-column-imoNumber mat-column-imoNumber ng-star-inserted">
             <!----><span _ngcontent-epp-c110="" class="ng-star-inserted">00121</span><!---->
          </td>
          <td _ngcontent-epp-c110="" role="gridcell" mat-cell="" class="mat-cell cdk-cell cdk-column-vouageId mat-column-vouageId ng-star-inserted">
             <!----><span _ngcontent-epp-c110="" class="ng-star-inserted">TBD</span><!---->
          </td>
          <td _ngcontent-epp-c110="" role="gridcell" mat-cell="" class="mat-cell cdk-cell cdk-column-lastValidityDate mat-column-lastValidityDate ng-star-inserted">
             <!----><span _ngcontent-epp-c110="" class="ng-star-inserted">2035-10-25</span><!---->
          </td>
          <!---->
       </tr>
       <!----><!---->
    </tbody>

Leave a Comment