我正在运行数据驱动框架(TestNG) 我想在下拉菜单中将excel单元格值与预先选择的值进行比较
这是下拉菜单HTML代码
select id="ctl00_ContentPlaceHolder1_ddlCalculation"class="normalText"
style="width:100%;"
onchange="javascript:LoadMethods(this.value);CallonChange(this.value,'spn_ddlCalculation');return false;" disabled="disabled" name="ctl00$ContentPlaceHolder1$ddlCalculation"
<option value="0" selected="selected">--- Select ---</option>
<option value="f">Formula Based</option>
<option value="m">Formula Based with Matrix Table</option>
<option value="q">Quantity Based</option>
<option value="t">Time Based</option>
</select>
这是我写的Selenium Code
WebElement DDmenu = driver.findElement(By.id(WebelementID));
String Content = TxtBoxContent.getAttribute("Option");
String ExcelData = Generic.getXlCellValue(xlpath, sheetName, rownum, cellnum);
if (Content.equals(ExcelData))
{
Reporter.log(LocationName+" Data Verification -- PASS",true);
}
else
{
Assert.fail(LocationName+"Data Verification -- Failed");
}
未能比较请帮助
答案 0 :(得分:1)
选择选择=新选择(DDmenu);
WebElement选项= select.getFirstSelectedOption();
String Content = option.getText();
String ExcelData = Generic.getXlCellValue(xlpath,sheetName,rownum, cellnum);
if(Content.equals(ExcelData))
{
Reporter.log(LocationName +“Data Verification - PASS”,true);
}
否则
{
Assert.fail(LocationName +“数据验证 - 失败”);
}