首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何与不匹配的给定值进行比较?

如何与不匹配的给定值进行比较?
EN

Stack Overflow用户
提问于 2019-10-17 20:02:15
回答 1查看 67关注 0票数 1

对于脚本语言来说,在类型记录中使用枚举和if else语句有问题。作为一种替代,我使用的是开关情况,而不是其他条件。

我试过了!==,!===,这似乎不管用。如果条件不等于比较值,则枚举的第一个索引不起作用,除非我做了它。

代码语言:javascript
复制
public static async getElementByLocatorType(locatorType: customLocators, locatorValue: string, expectedText?: string) {
        if (locatorType! === customLocators.CSS) {
            return  element(by.css(locatorValue));
        } else if (locatorType === customLocators.XPATH) {
            return element(await by.xpath(locatorValue));
        } else if (locatorType === customLocators.CSSTEXT) {
            return  element(by.cssContainingText(locatorValue, expectedText));
        } else if (locatorType === customLocators.LINKTEXT) {
            return  element(by.linkText(locatorValue));
        } else if (locatorType === customLocators.BUTTONTEXT ) {
            return  element(by.buttonText(locatorValue));
        } else if (locatorType === customLocators.PARTIALBUTTONTEXT) {
            return  element(by.partialButtonText(locatorValue));
        } else if (locatorType === customLocators.PARTIALLINKTEXT ) {
            return  element(by.partialLinkText(locatorValue));
        } else {
            logger.info('Cannot find any locator listed above');
        }

    }


 export enum customLocators {
     'CSS', 'XPATH', 'CSSTEXT', 'LINKTEXT', 'BUTTONTEXT', 'PARTIALBUTTONTEXT', 'PARTIALLINKTEXT'
 }

没有找到的元素(by.css)其他元素工作得很好,除了(枚举的第一个索引) locatorType === customLocators.CSS

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-18 14:16:33

如前所述,我使用了开关箱作为一种可以正常工作的替代方案。

代码语言:javascript
复制
  public static async  getElementByLocatorType(locatorType: customLocators, 
    locatorValue: string, expectedText?: string) {
            switch (locatorType) {
                case customLocators.CSS:
                   return  element(by.css(locatorValue));
                    break;
                case customLocators.XPATH:
                    return element(by.xpath(locatorValue));
                    break;
                case customLocators.LINKTEXT:
                    return element(by.linkText(locatorValue));
                    break;
                case customLocators.BUTTONTEXT:
                    return element(by.buttonText(locatorValue));
                    break;
                case customLocators.CSSTEXT:
                    return element(by.cssContainingText(locatorValue, expectedText));
                    break;
                case customLocators.PARTIALLINKTEXT:
                    return element(by.partialLinkText(locatorValue));
                    break;
                case customLocators.PARTIALBUTTONTEXT:
                    return element(by.partialButtonText(locatorValue));
                    break;
                default:
                    logger.info('browser : ' + locatorType + ' is invalid, Please check the selector name..');
            }
        }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58439961

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档