2016-12-23 29 views
-2

我想從一個下拉選擇角度e2e測試使用量角器的選項。
這裏是選擇選項的代碼片段:
無法在下拉選擇選項protractorjs e2e測試

<div class="width70"> 
    <span title="" class="k-widget k-dropdown k-header width100 ng-scope ng-dirty ng-valid-parse ng-touched ng-invalid ng-invalid-required k-invalid" unselectable="on" role="listbox" aria-haspopup="true" aria-expanded="true" tabindex="0" aria-owns="" aria-disabled="false" aria-readonly="false" aria-busy="false" style="" aria-activedescendant="9e8e661a-e100-4c17-bceb-3de8ac876316"> 
    <span unselectable="on" class="k-dropdown-wrap k-state-default"><span unselectable="on" class="k-input ng-scope">Select Customer</span><span unselectable="on" class="k-select"><span unselectable="on" class="k-icon k-i-arrow-s">select</span></span></span> 
    <select kendo-drop-down-list="" required="" name="customer" ng-model="arrayView.selectedCustomer" k-options="arrayView.customerList" k-rebind="arrayView.customerList" validationmessage="Select Customer" class="width100 ng-scope ng-dirty ng-valid-parse ng-touched ng-invalid ng-invalid-required k-invalid" data-role="dropdownlist" style="display: none;" aria-invalid="true"> 
     <option value="" selected="selected">Select Customer</option> 
     <option value="615">option A</option> 
     <option value="139">option B</option> 
     <option value="1476">option C</option> 
     <option value="570">option D</option>......` 


我已經嘗試了幾乎所有的下頁
How to select option in drop down protractorjs e2e tests
他們都不似乎是爲我工作提到的方法。
我甚至無法找到'select'('option'的父項)標籤。
但是我成功地能夠點擊div.span.span元素。

另外,當我點擊下拉菜單時,我會看到一個搜索框以及所有選項。我附上相同的圖片
enter image description here 請幫助我。我嘗試了幾種方法,似乎沒有任何工作。

+0

您是使用angularjs還是kendo.js。 –

+0

我正在使用angularjs –

+0

不太確定,Wappalyzer將「Angular material」和「Kendo UI」顯示爲Web框架。 –

回答

1
var selectOptionFromDrpdwn = function (ngModelLocator, option) {  
    //arguments are strings 
    element(by.model(ngModelLocator)) 
    .element(by.cssContainingText('option', option)) 
    .click(); 
} 

說明:

上述兩個參數:定位器和選項的被選擇的值。定位器可以是任何東西,但是在這裏我使用ng-model,如果您使用其他任何東西,則必須相應地更改定位器功能。

在找到的元素中,我發現要使用[cssContainingText locator] [1]單擊該選項。唯一的缺點是選項值是完全鍵入的,它不能取部分值名稱。否則,您可以使用選項編號邏輯並相應地傳遞一個數字以便點擊:

element(by.model(ngModelLocator)).all(by.tagName('option').get(optionNumber).click(); 
+2

雖然此代碼片段可能會解決問題,但[包括解釋](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)確實有助於提高帖子的質量。請記住,您將來會爲讀者回答問題,而這些人可能不知道您的代碼建議的原因。 – DimaSan

+0

已更新@DimaSan –