[英]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.