Javascript 检查对象是否为GragratorJS中的定位器或ElementFinder

Javascript 检查对象是否为GragratorJS中的定位器或ElementFinder,javascript,node.js,protractor,element,Javascript,Node.js,Protractor,Element,我需要写一个函数来检查一个对象是定位器还是ElementFinder。我尝试使用typeof,但没有成功。有什么想法吗?您可以尝试使用ElementFinder可用的功能,但定位器不可用 var isElementFinder = function(obj) { try { // you don't care about this output, just that the function can execute obj.getTagName();

我需要写一个函数来检查一个对象是定位器还是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的实例。那只是猜测。