我需要编写一个函数来检查对象是定位器还是ElementFinder。我试图使用typeof,但它没有成功。有什么想法吗?
答案 0 :(得分:0)
您可以尝试使用可用于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;
}
}