量角器:获取没有特定 class 的元素

Protractor : get element which has not a specific class

我正在尝试进行端到端测试以处理下一个示例:

HTML:

<div ng-if="selectedItem">
  <span class-"xxx">This is line 1</span>
  <span class="xxx yyy">This is line 2</span>
</div>

量角器:

..
element.findByCss('div[ng-if="selectedItem"] span[class!="yyy"]');
..

出现以下错误:

Failed: invalid element state: Failed to execute 'querySelectorAll' on 'Document': 'div[ng-if="selectedItem"] span[class!="yyy"]' is not a valid selector.

虽然选择器与 jQuery 一起使用..我知道它不一样。但我似乎无法找到如何用量角器

排除class

使用not取反pseudo-class:

$('div[ng-if=selectedItem] span:not(.yyy)');

或者,在您的情况下,您还可以匹配完整的 class 属性值:

$('div[ng-if=selectedItem] span[class=xxx]');

或者,如果适用,您也可以通过索引获得第一个span

$$('div[ng-if=selectedItem] span.xxx').first();

$ 这里是 element(by.css()), $$ 的快捷方式 - element.all(by.css())