复选框未选中,尽管在运行测试用例时未显示错误有人可以提出建议以获得解决方案

问题描述

通过定位器:有人可以提出建议以解决此问题

 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);
}

页面包含定义by定位符的方法

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">&nbsp;Bicycle  

            <input id="tricycle-checkBox" type="checkBox" name="vehicle2" value="Tricycle" disabled="">&nbsp;Tricycle   

            <input id="bike-checkBox" type="checkBox" name="vehicle3" value="Bike">&nbsp;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">&nbsp;Hatchback       

            <input id="sedan-checkBox" type="checkBox" name="vehicle5" value="Sedan">&nbsp;Sedan
                <input id="van-checkBox" type="checkBox" name="vehicle6" value="Van">&nbsp;Van

            <input id="suv-checkBox" type="checkBox" name="vehicle7" value="SUV">&nbsp;SUV

            <input id="truck-checkBox" type="checkBox" name="vehicle8" value="Truck">&nbsp;Truck    

        </div>

解决方法

IF循环标准不正确。试试这个,

for(int i=0;i<opts.size();i++)

     {
         if(opts.get(i).gettext().equals(value))

         {
             opts.get(i).click();
         }
     }

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...