检查对象是 ProtractorJS 中的定位器还是 ElementFinder
Checking if an object is locator or ElementFinder in ProtractorJS
我需要编写一个函数来检查对象是定位器还是 ElementFinder。我尝试使用 typeof 但没有成功。有什么想法吗?
您可以尝试使用对 ElementFinder 可用但对定位器不可用的函数。
var isElementFinder = function(obj) {
try {
// you don't care about this output, just that the function can execute
obj.getTagName();
return true;
} catch(e) {
// for any object that is not an ElementFinder,
// this should throw an error that 'getTagName' is not defined
return false;
}
}
我需要编写一个函数来检查对象是定位器还是 ElementFinder。我尝试使用 typeof 但没有成功。有什么想法吗?
您可以尝试使用对 ElementFinder 可用但对定位器不可用的函数。
var isElementFinder = function(obj) {
try {
// you don't care about this output, just that the function can execute
obj.getTagName();
return true;
} catch(e) {
// for any object that is not an ElementFinder,
// this should throw an error that 'getTagName' is not defined
return false;
}
}