简体   繁体   English

尝试进行申请时,为什么会收到一条消息,指出“对象不是函数”?

[英]Why do I get a message saying “Object is not a function” when I try to do an apply?

I set up some variables to hold page elements: 我设置了一些变量来保存页面元素:

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

I have this function call: 我有这个函数调用:

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

What I wanted to do was make a call to another function like this: 我想做的是调用另一个函数,如下所示:

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);
    });
}

But I am getting a strange error pointing to the line with the xpath. 但是我遇到一个奇怪的错误,它指向与xpath对应的行。 The error is 错误是

TypeError: Object is not a function

I cannot see what this means. 我看不出这是什么意思。 Can someone suggest what I might be doing wrong? 有人可以建议我可能做错了吗? I'm also not sure what is the purpose of the self after apply( ? 我也不确定申请后自我的目的是什么?

You are redefining element in the local scope. 您正在重新定义本地范围内的element Instead name your input parameter elem for example like so: 而是将输入参数命名为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 + '"]'));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我得到一条消息说forEach不是函数? - Why do I get a message saying forEach is not a function? 尝试将中间件功能导出到module.exports对象时,为什么会得到“下一个不是功能”的信息? - Why do I get 'Next is not a function' when I try to export a Middleware function to module.exports object? 为什么当我尝试将这些数字相乘时会得到 NaN? - why do i get NaN when i try to multiply these numbers? 当我尝试向函数传递已传递数组的长度时,为什么会出现错误? - Why do I get error when I try to alert the length of the passed array to the function? 为什么当我拨打 http 时,会收到一条错误消息说我的 url 不是字符串? - Why, when I make an http call, do I get an error saying my url is not a string? 为什么我总是收到错误消息,指出对象属性未定义? - Why do I keep getting an error saying an object property is undefined? 为什么我收到一个错误说拆分未定义? - Why do I get an error saying split undefined? 为什么我在Javascript中收到错误消息对象没有方法? - Why do I get the error message Object has no method in Javascript? 为什么我会为此功能获得双控制台消息? - Why do I get a double console message for this function? 为什么我会在控制台中收到有效的 function 的错误消息? - Why do I get an error message in console for a function that works?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM