问题描述
通过定位器:有人可以提出建议以解决此问题
By ihaveoption2wheeler = By.xpath("//div[@id='twoWheelVehicles']/input[@type='checkBox']");
测试页具有测试用例:
@DataProvider
public Object[][] selectcheckBox()
{
Object[][] data = ExcelUtil.getTestData(AppConstants.checkBox_select);
return data;
}
@Test(priority=1,dataProvider="selectcheckBox")
public void clickoncheckBox(String ihave)
{
dropdownpage.selectihaveoption(ihave);
}
public void selectihaveoption(String checkBoxoption)
{
elementutils.waitforElement(ihaveoption);
elementutils.clickoncheckBoxradiobutton(ihaveoption,checkBoxoption);
}
Utils:
public void clickoncheckBoxradiobutton(By locator,String value)
{
List<WebElement> opts = driver.findElements(locator);
int sizeofcheckBox = opts.size();
for(int i=0;i<opts.size();i++)
{
if(opts.equals(value))
{
opts.get(i).click();
}
}
}
HTML:
<div id="twoWheelVehicles" class="col-md-6 col-xs-10 col-xs-offset-1">
<input id="bicycle-checkBox" type="checkBox" name="vehicle1" value="Bicycle"> Bicycle
<input id="tricycle-checkBox" type="checkBox" name="vehicle2" value="Tricycle" disabled=""> Tricycle
<input id="bike-checkBox" type="checkBox" name="vehicle3" value="Bike"> Bike
<div id="fourWheelVehicles" class="col-md-6 col-xs-10 col-xs-offset-1">
<input id="hatchback-checkBox" type="checkBox" name="vehicle4" value="Hatchback"> Hatchback
<input id="sedan-checkBox" type="checkBox" name="vehicle5" value="Sedan"> Sedan
<input id="van-checkBox" type="checkBox" name="vehicle6" value="Van"> Van
<input id="suv-checkBox" type="checkBox" name="vehicle7" value="SUV"> SUV
<input id="truck-checkBox" type="checkBox" name="vehicle8" value="Truck"> Truck
</div>
解决方法
IF循环标准不正确。试试这个,
for(int i=0;i<opts.size();i++)
{
if(opts.get(i).gettext().equals(value))
{
opts.get(i).click();
}
}