【问题标题】:identifying image object using css for protractor automation使用 css 识别图像对象以实现量角器自动化
【发布时间】:2014-10-07 15:55:28
【问题描述】:

我正在使用量角器进行 Angular js 自动化。我正在尝试使用 css 标识符从以下元素结构中获取“fa fa-something”文本-

<div class="Itemlistcontainer">
      <ul class="itemlist sortlist ui-sortable">
      <!-- ngRepeat: Item in Items | orderBy:CustomSort:false --><li ng-repeat=" Item in Items | orderBy:CustomSort:false" ng-show="!searchinput || ([Item.Name]|filter:searchinput).length" ng-class="{ 'itemdisabled' : !CanUseTask(Item) || deactivate }" class="ng-scope ui-draggable">
        <div bo-attr="" bo-attr-id="Item.Id" bo-attr-title="Item.Details | html2string" class="label itemlabel" id="3d991564-a1a9-49ab-8659-a26e00fbfae6" title="Blah blah blah.">
          <span>
            <i ng-class="itemIconClass(Item)" style="margin-right: 5px;" class="fa fa-something"></i>
          </span><span bo-text="item.Name | ellipse : 32">Item Name</span>
        </div>
      <!--ngRepeat: Item in Items....and the list goes on 

我需要知道这个“fa fa-something”是在哪个 Items in Items 下找到的。我正在使用element(By.css('ul.itemlist i.itemIconClass(Item)').getAttribute('class').getText() 这不起作用。

【问题讨论】:

  • getAttribute('class').getText() 永远不会工作,你对那里的class 属性没有做任何事情,getText() 工作因为ElementFinder 是可链接的,仅此而已。

标签: css angularjs css-selectors protractor


【解决方案1】:
element(By.css('ul.itemlist i.itemIconClass(Item)').getAttribute('class').getText() 

当您尝试在量角器元素选择器中插入角度模板表达式时无法工作

我认为你需要:

element(By.css('ul.itemlist i.fa.fa-something').getAttribute('class').getText() 

而要确定what Item in Items was this 'fa fa-something' found,也许你需要一个ID(这样会更容易阅读,不需要通过提取fa fasomething等来解析类属性...

【讨论】:

  • 对我不起作用,因为我需要根据您的解决方案在 css 标识符中使用 'fa.fa-something'。
  • 您的问题不清楚,添加更多单元测试代码
猜你喜欢
  • 1970-01-01
  • 2013-07-06
  • 2012-06-20
  • 2018-03-15
  • 2010-12-02
  • 2020-04-28
  • 1970-01-01
  • 2011-08-13
  • 2020-07-13
相关资源
最近更新 更多