In below code, not able to click or getText of the radiobutton using xpath & id both.
Please help me to perform above operations.
<section class="col-md-12 mb5">
<div class="well well-cust">
<label class="radio-inline pl0">
<input type="radio" name="project_task" value="A" onclick="Javascript:projtasks();" id="radio1"> Projects Tasks</label>
<label class="radio-inline">
<input type="radio" name="project_task" value="B" onclick="nonprojtasks(); " id="radio2"> Non Projects Tasks</label>
<label class="radio-inline">
<input type="radio" name="project_task" value="C" checked="checked" onclick="assignedTasks();" id="radio3"> Assigned Tasks</label>
<label class="radio-inline">
<input type="radio" name="project_task" value="D" onclick="issueAssigned(); " id="radio4"> Issues Assigned</label>
</div>
</section>
Tried to click on the element using xpath & id both.
I tried with below code:
//Import data for Radiobutton
String Radiobutton_val = formatter.formatCellValue(sheet.getRow(i).getCell(1));
System.out.println("Radio button 1 = "+driver.findElement(By.xpath("//*[@id=\"radio1\"]")).getText());
System.out.println("Radio button 2 = "+driver.findElement(By.xpath("//*[@id=\"radio2\"]")).getText());
if(driver.findElement(By.id("radio1")).getText().equals(Radiobutton_val)) {
driver.findElement(By.xpath("//*[@id=\"radio1\"]")).click();
} else if(driver.findElement(By.id("radio2")).getText().equals(Radiobutton_val)){
driver.findElement(By.xpath("//*[@id=\"radio2\"]")).click();
}
I expect that it should getText of the radiobutton & based on the getText value it should click on the specified radio button