以下代码使用JXL插件读取电子表格单元格值,然后将这些值与页面上的值进行比较,并从组合框中选择匹配值。
如何调整此代码以使用单选按钮?
String valDesejado = aquisicaoAparelho;
boolean variavelVerificadora1 = false; // use boolean instead of int set to 0/1
Select verificaOpt = new Select(driver.findElement(By.name("aquisicaoAparelho")));
System.out.println("Tamanho: " + verificaOpt.getOptions().size());
// as this loops, the variable 'option' contains the current loops' OPTION element
// you don't need to select the option to get its text so this loop should be much faster
// it selects the OPTION once the correct one is found
for (WebElement option : verificaOpt.getOptions())
{
if (valDesejado.equalsIgnoreCase(option.getText()))
{
verificaOpt.selectByVisibleText(option.getText()); // select the OPTION match
variavelVerificadora1 = true; // set the boolean to true to indicate we found a match
break; // exits the for loop
}
}
if (!variavelVerificadora1) // this is the equivalent of variavelVerificadora1 == false, it's basically saying if not true
{
System.out.println("ALERTA: The Option" + valDesejado + " no comboBox \"aquisicaoAparelho\" not found.");
}
Html代码页面:
<td align="left" class="label">
<input type="radio" value="S" name="aquisicaoAparelho">Yes
<input type="radio" value="N" name="aquisicaoAparelho">Not
<input type="radio" value="A" name="aquisicaoAparelho">both
</td>