在ProtractorJS中检查对象是定位器还是ElementFinder

时间:2017-04-23 18:07:55

标签: javascript node.js protractor element

我需要编写一个函数来检查对象是定位器还是ElementFinder。我试图使用typeof,但它没有成功。有什么想法吗?

1 个答案:

答案 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;
    }
}