2015-10-19 29 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(); 

希望它能幫助。