首页 > 解决方案 > 作为 E/启动器出现错误 - 错误:TypeError:无法读取未定义的属性“0”

问题描述

执行此代码时出现以下错误-

E/启动器 - 错误:TypeError:无法读取未定义的属性“0”

需要您的帮助来解决 Protractor 版本 5.4.3 中的此问题

let objectLocator = function(){

    var webElement = null;

    //find locator using provided locator type and locator value
    this.findLocator = function (locator, value) {
        var locatorType = locator[0];
        var locatorValue = locator[1];
        if (typeof locatorType !== 'undefined') {
            if (locatorValue.includes('#REPLACE#')) {
                locatorValue = locatorValue.replace('#REPLACE#', value);
            }
            if (locatorType == 'id') {
                if (locatorValue !== 'undefined') {
                    this.webElement = element(by.id(locatorValue));
                }
            } else if (locatorType == 'name') {
                if (locatorValue !== 'undefined') {
                    this.webElement = element(by.name(locatorValue));
                }
            } else if (locatorType == 'xpath') {
                if (locatorValue !== 'undefined') {
                    this.webElement = element(by.xpath(locatorValue));
                }
            } else if (locatorType == 'css') {
                if (locatorValue !== 'undefined') {
                    this.webElement = element(by.css(locatorValue));
                }
            }
        }
        return this.webElement;
    };
};

module.exports = new objectLocator();

标签: protractor

解决方案


推荐阅读