【问题标题】:Find element by css winch is not active using protractor angular使用量角器角度通过 css 绞盘查找元素未激活
【发布时间】:2019-02-25 20:19:58
【问题描述】:

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

在我的 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);

但它不点击也不工作。我不确定在这种情况下出了什么问题。

【问题讨论】:

    标签: css angular css-selectors protractor


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2016-03-04
      • 2015-11-08
      • 1970-01-01
      • 1970-01-01
      • 2016-03-25
      • 1970-01-01
      • 2015-12-28
      • 2016-01-22
      • 1970-01-01
      相关资源
      最近更新 更多