Protractor 如何在量角器中选择开关按钮

Protractor 如何在量角器中选择开关按钮,protractor,Protractor,我正在使用量角器在角度应用程序上运行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="boo

我正在使用量角器在角度应用程序上运行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>
ON
关

我猜不出你页面的DOM。首先,我不想使用xpath。量角器
中的IMHO应为小写

我假设在单击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();
    }
}