【问题标题】:protractor span repeated cycle量角器跨度重复循环
【发布时间】:2018-06-28 19:33:34
【问题描述】:

在下面的代码中,我如何获得“开始测试”的值?

<div class="nea-sidebar" _ngcontent-c2="">
<a class="sidebar-item active" href="#/test" _ngcontent-c2="" routerlinkactive="active" ng-reflect-router-link="test" ng-reflect-router-link-active="active">
<i class="sidebar-icon fas fa-play" _ngcontent-c2="" ng-reflect-klass="sidebar-icon fas" ng-reflect-ng-class="fa-play"></i>
<span class="sidebar-label" _ngcontent-c2="">Start Test</span></a>

<a class="sidebar-item" href="#/sequences" _ngcontent-c2="" routerlinkactive="active" ng-reflect-router-link="sequences" ng-reflect-router-link-active="active">
<i class="sidebar-icon fas fa-project-diagram" _ngcontent-c2="" ng-reflect-klass="sidebar-icon fas" ng-reflect-ng-class="fa-project-diagram"></i>
<span class="sidebar-label" _ngcontent-c2="">Sequences</span></a>

.
.
.
/>

我正在使用: element(by.className('sidebar-label')).isDisplayed().then(function(isVisible) { 如果(是可见的){ // 测试 -- validar caminho, icon ... label sidebar-label expect(element(by.className('sidebar-label')).getAttribute('_ngcontent-c2')).toBe('开始测试'); }

但它返回失败,因为“ - 预期''是'开始测试'。

【问题讨论】:

  • 不要发布代码截图,将相关代码复制到您的问题正文中。
  • 我刚改了。谢谢。

标签: jasmine protractor


【解决方案1】:

你可以这样做:

element(by.css('.nea-sidebar '))
.element(by.cssContainingText('.sidebar-label', 'Start Test')).isDisplayed()
   .then(function(isDisplayed) {
     expect(isDisplayed).toBeTruthy();
 });

by.cssContainingText(selector, text) 查找给定selector 包含给定text 的元素。如果显示该元素,则表示量角器实际上找到了包含此类文本的元素。

【讨论】:

  • 谢谢。我测试了它,由于“使用定位器找不到元素:by.cssContainingText(“sidebar-label”,“Start Test”)”而失败
  • 我检查了 cssContainingText 的帮助,它缺少一个 .在侧边栏之前它可以工作:D
  • 啊,是的,小错字。我调整了答案。也可以将答案标记为已接受,以便其他用户看到它已成功回答。
  • 怎么做标记?你知道如何从代码示例中获取 hrf 吗?
  • 如果我理解正确,您想从&lt;a&gt; 标记中获取href 属性吗?如果是,您可以尝试以下操作:element.all(by.css('.sidebaritem').first().getAttribute('href').then(function(value) { console.log('href value:' , value); }); 我在这里使用element.all(),因为存在与选择器.sidebar-item 匹配的多个元素。
猜你喜欢
  • 2017-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-18
  • 1970-01-01
  • 2015-12-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多