当我尝试申请时,为什么会收到“对象不是函数”的消息?

时间:2014-07-13 09:01:39

标签: javascript

我设置了一些变量来保存页面元素:

this.examStatusSelect = element(by.id('examStatusSelect'));
this.examTypeSelect = element(by.id('examTypeSelect'));

我有这个函数调用:

    dom.checkGrid('* check', 0, [
        [page.examStatusSelect, 0],
        [page.examTypeSelect, 0],
    ]);

我想要做的是调用另一个这样的函数:

var Dom = function () {

var self = this;

this.getSelectOption = function (element, value) {
    var id = element.locator_.value;
    return element(by.xpath('//select[@id="' + id + '"]/option[@value = "' + value + '"]'));
}

this.checkGrid = function (label, expectedCount, params) {
    it(label + ': Check for ' + expectedCount + ' grid rows', function () {
        for (var i = 0; i < params.length; ++i) {
            self.getSelectOption.apply(self, params[i]).click();
        }
        page.retrieveButton.click();
        expect(page.row.count()).toBe(expectedCount);
    });
}

但是我收到一个指向xpath行的奇怪错误。错误是

TypeError: Object is not a function

我看不出这意味着什么。有人可以建议我可能做错了吗?申请后我也不确定自我的目的是什么(?

1 个答案:

答案 0 :(得分:3)

您正在本地范围内重新定义element。而是将输入参数命名为elem,例如:

this.getSelectOption = function (elem /* local scope */, value) {
    var id = elem.locator_.value; /* elem is local scope here */
    /* element is from the not local scope 
       (might be global, could also be from a closure) */
    return element(by.xpath('//select[@id="' + id + '"]/option[@value = "' + value + '"]'));
}