2017-04-23 32 views
0

我需要编写一个函数来检查对象是定位器还是ElementFinder。我试图使用typeof,但它不成功。任何想法?检查对象是否位于ProtractorJS中的定位器或ElementFinder

+1

你可以添加相关的代码吗? – Grasshopper

+0

是的,这很难帮助弄清楚发生了什么。相关代码,量角器配置,控制台输出,错误消息等。在问题的当前状态下,我可以给你的最佳答案是阅读文档。你可以尝试'instanceof ElementFinder'。这只是一个猜测。 – cnishina

回答

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; 
    } 
} 
相关问题