-1

这是我的 html 页面的样子:

<table class="service ng-scope">
  <tbody>
    <tr>
      <th>
    24 HOUR TREND
      </th>
    </tr>
  </tbody>
</table>

我正在尝试使用量角器在我的测试中打印文本“24 小时趋势”。

这是我的测试代码:

describe("print text", function () {

    var ptor;

    beforeEach(function() {
        // get protractor instance
        ptor = protractor.getInstance();
    });

    it("print text", function() {
        var modal;
        // load the url
        ptor.get("/");
        var elements = ptor.findElements(protractor.By.className('service ng-scope'));

        < -- Problem here --- what to do --- >

        // disable jQuery animation effects
        ptor.driver.executeScript("$.fx.off = true;");
});
4

2 回答 2

2

你可以做:

ptor.get("/");
var serviceTable = ptor.findElement(protractor.By.className('service ng-scope'));
serviceTable.getText().then(function(text) {
  console.log(text);
});
于 2014-01-10T22:48:39.397 回答
0

谢谢,这行得通。但是我得到了:

消息:InvalidSelectorError:不支持复合类名。考虑搜索一个类名并过滤结果或使用 CSS 选择器。有关此错误的文档,请访问:http ://seleniumhq.org/exceptions/invalid_selector_exception.html 构建信息:版本:'2.37.0',修订:'a7c61cb',时间:'2013-10-18 17:14 :00'

所以最终只使用:

protractor.By.className('ng-scope')

于 2014-01-13T18:21:00.753 回答