2017-06-01 43 views
0

我在使用量角器的角度應用程序上運行E2E。如何編寫切換按鈕的腳本。如何選擇量角器中的開關按鈕

<span class="bootstrap-switch-handle-on bootstrap-switch-primary" style="width: 41px;">ON</span> 
<span class="bootstrap-switch-label" style="width: 41px;">&nbsp;</span> 
<span class="bootstrap-switch-handle-off bootstrap-switch-default" style="width: 41px;">OFF</span> 

回答

0

我無法猜測您的頁面的DOM。首先,我寧願不使用xpath。恕我直言,量角器by應該是小寫。

我假設在單擊span變化的元素類後。

也許嘗試某事像那:

const button = element(by.css('span.bootstrap-switch-primary')); 
button.getAttribute('class').then((classes) => { 
    if (classes.indexOf('bootstrap-switch-handle-on') === -1) { 
     return button.click(); 
    } 
}