按ID查找元素在量角器中不起作用

时间:2014-10-17 20:28:44

标签: selenium protractor

当我按ID使用find元素时,它在我的代码中不起作用。

- 这是显示4个标签的HTML。在每个选项下都有导航选项,其中包含id。 4个标签中的每一个也都有id。但使用它们进行识别是行不通的。

HTML:

<nav id="monitoring-tab" class="pure-menu pure-menu-open pure-menu-horizontal ng-scope">
  <ul>
    <li id="now-tab" ui-sref-active="pure-menu-selected" ng-hide="hideTab.now" class="ng-hide">
      <a ui-sref="app.monitoring.real-time" href="#/monitoring/real-time">
        Now</a>
    </li>
    <li id="day-tab" ui-sref-active="pure-menu-selected" class="pure-menu-selected">
      <a ui-sref="app.monitoring.historical.day" href="#/monitoring/historical/day">
        Day</a>
    </li>
    <li id="month-tab" ui-sref-active="pure-menu-selected">
      <a ui-sref="app.monitoring.historical.month" href="#/monitoring/historical/month">
        Month</a>
    </li>
    <li id="year-tab" ui-sref-active="pure-menu-selected">
      <a ui-sref="app.monitoring.historical.year" href="#/monitoring/historical/year">
        Year</a>
    </li>
    <li id="lifetime-tab" ui-sref-active="pure-menu-selected">
      <a ui-sref="app.monitoring.historical.lifetime" href="#/monitoring/historical/lifetime">
        Lifetime</a>
    </li>
  </ul>
</nav>

<div id="date-range" ng-hide="stateName =='app.monitoring.historical.lifetime'" class="ng-scope">
  <span>
    <a id="historical-nav-prev" ui-sref="app.monitoring.historical.day({date:'2014-10-16'})" href="#/monitoring/historical/day?date=2014-10-16">
      <i class="fa fa-chevron-left"></i>
    </a>
  </span>
  <span class="ng-binding">Fri, Oct 17, 2014</span>
  <span ng-show="historicalNav.nextDateBtnShown" class="ng-hide">
    <a id="historical-nav-next" ui-sref="app.monitoring.historical.day({date:''})" href="#/monitoring/historical/day?date=">
      <i class="fa fa-chevron-right"></i>
    </a>
  </span>
</div>

MyCode:

it('Should click on the previous day', function() {

    element(by.id('historical-nav-prev')).click();
    });

错误:

   NoSuchElementError: No element found using locator: By.id("historical-nav-p
rev")

这里有什么问题?我使用的大部分内容都不起作用。

0 个答案:

没有答案