2015-10-19 63 views
0

我试图签入RadioButtonList的值:如何用量角器选择radiobuttonlist中的值?

<ul id="rbgHomeOccupier" class="radio-group cols-6"> 
      <li class="radio-group-button"> 
       <input type="radio" id="homeOccupierInjuredYes" class="radio-group-input" value="true" 
        tabindex="" name="homeOccupierInjured" ng-model="claim.damage.homeOccupierInjured" required> 
       <label for="homeOccupierInjuredYes" class="radio-group-label">Yes</label> 
      </li> 
      <li class="radio-group-button"> 
       <input type="radio" id="homeOccupierInjuredNo" class="radio-group-input" value="false" tabindex="" 
        name="homeOccupierInjured" 
        ng-model="claim.damage.homeOccupierInjured" required> 
       <label for="homeOccupierInjuredNo" class="radio-group-label">No</label> 
      </li> 
</ul> 

这是我的尝试:

element.all(by.id('rbgHomeOccupier')).get(1).click(); 

不过,我得到一个错误说那里只有一个元素是:

Failed: Index out of bound. Trying to access element at index: 1, but there are only 1 elements that match locator By.id("rbgHomeOccupier") 

如何选择第一个值,即'是'?

回答

0

您应该对input元素执行click()操作,而不是对列表元素执行操作。此外,元素定位器by.id('rbgHomeOccupier')不正确,因为在DOM中只有一个元素与该定位器相关,并且element.all()尝试使用该定位器查找DOM中的所有元素。下面是如何使用第一无线电输入get()功能使用适当的定位,然后点击它来获得 -

element.all(by.css('#rbgHomeOccupier input[type="radio"]')).get(0).click(); 
//Note: get() is a zero based index and so to click on the first element you need to pass 0 to the function 

但是有,如果你有在DOM ID homeOccupierInjuredYes只有一个输入元素的简单方法。在这种情况下,你可以直接调用它,而无需任何get()功能 -

element(by.id('homeOccupierInjuredYes')).click(); 

希望它能帮助。