css - 通过 css winch 查找元素未使用 Protractor Angular 激活

标签 css angular css-selectors protractor

我正在使用 Protractor 自动测试我的应用程序。我通过将 css 类定义为 html 来获取元素。现在,我有一个垫子表单字段。在那个垫子表单字段中,我有很多垫子选项。我想为此选项实现随机选择来测试我的应用程序。我正在详细解释。

在我的 HTML 类中

<mat-form-field>
   <mat-select class="t-day" matInput placeholder="{{ 'Day' | translate }}" [(ngModel)]="settings.day" name="day">
   <mat-option class="t-hour-option" *ngFor="let day of days" [value]="day.value">{{ day.text }}</mat-option>
  </mat-select>
</mat-form-field>

现在在测试课上,我首先点击进入字段,然后从中选择一个随机选项。我正在尝试这种方式。

 let dayfield = element(by.css('.t-day'));
 let picktime = element.all(by.css('.t-hour-option.mat-option:not(.t-hour-option.mat-option.mat-selected.mat-active)'));

    await click.onto(productionDayEnd)
    await productionDayEnd.isDisplayed();

    await click.onto(picktime);

但它没有点击并且不起作用。我不确定这种情况出了什么问题。

最佳答案

您正在使用 .mat-option 作为一个类,但它实际上是一个标签。
$$('mat-option.t-hour-option:not(.mat-active)');
$$('.t-hour-option:not(.mat-active'); 是一些潜在的解决方案。

但是,我没有看到名为 .mat-active 的类,尽管它可能会被渲染(angular 不是最好的)。如果 .mat-active 是一个像 .mat-option 这样的标签那么你会想要做
:not(mat-active)

关于css - 通过 css winch 查找元素未使用 Protractor Angular 激活,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52443449/

相关文章:

html - 调整窗口大小导致文本下推图像

javascript - 动态创建的 <div> 无法正确定位

html - 如何消除 Flexbox 中额外的容器间距?

javascript - 将父作用域添加到匿名函数 - JavaScript 到 Angular 2

css - 使用 CSS 多重组合器的最短方法是什么?

css - 为什么不能在 CSS 选择器中对后代进行分组?

html - 将文本放入内容栏?

Angular:如何捕获更改时的复选框状态

json - 在 rxjs ajax 回调中解析 JSON 不起作用

html - CSS 否定伪类 :not() for parent/ancestor elements