Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用量角器以布尔形式获取元素可用性状态_Javascript_Css_Angularjs_Node.js_Protractor - Fatal编程技术网

Javascript 使用量角器以布尔形式获取元素可用性状态

Javascript 使用量角器以布尔形式获取元素可用性状态,javascript,css,angularjs,node.js,protractor,Javascript,Css,Angularjs,Node.js,Protractor,我正在尝试使用“If”条件获取元素的当前状态,但不幸的是,我无法获取“true”或“false”结果,而是获取like(当元素可用时,我获取的结果为“true”,当元素不可用时,我获取的错误消息如下) 失败:使用定位器(css选择器、.alert message.ng binding.alert.alert成功)未找到任何元素 下面是我使用的代码 describe("test 1", function () { it("testing", function () {

我正在尝试使用“If”条件获取元素的当前状态,但不幸的是,我无法获取“true”或“false”结果,而是获取like(当元素可用时,我获取的结果为“true”,当元素不可用时,我获取的错误消息如下)

  • 失败:使用定位器(css选择器、.alert message.ng binding.alert.alert成功)未找到任何元素
下面是我使用的代码

describe("test 1", function () {
    it("testing", function () {
        var userCreationSuccessConfirmationMsg = element(by.className('alert-message ng-binding alert alert-success'));
        var userCreationFailureConfirmationMsg = element(by.className('alert-message ng-binding alert alert-danger'));

        browser.driver.get(testData.UBETURL);
        login.loginToUbet('sysadmin', 'password');
        console.log('Somesh');
        element(by.linkText('Configuration')).click();
        element(by.linkText('Create New User')).click();
        element.all(by.id('saveUser')).first().click();
        console.log(expect(userCreationSuccessConfirmationMsg.isDisplayed()));
        userCreationSuccessConfirmationMsg.isDisplayed().then(function (status) {
            if (status) {
                console.log(status);
            } else {
                console.lgo(status);
            }
        });
    });
});

如何使用if获取布尔值形式的元素可用性状态,请在这里指导我???

如果您知道成功是在(且仅在)返回的状态为“true”时,那么您只需检查该字符串的确切文本即可:

userCreationSuccessConfirmationMsg.isDisplayed().then(function (status) {
    if (status === 'true') {
        ...
    }
});

如果您知道当(且仅当)返回的状态为“true”时成功,则只需检查该字符串的确切文本即可:

userCreationSuccessConfirmationMsg.isDisplayed().then(function (status) {
    if (status === 'true') {
        ...
    }
});

您可以使用
isPresent
确定页面中是否存在元素:

userCreationSuccessConfirmationMsg.isPresent().then(function (status) {
    if (status) {
        console.log('present');
    } else {
        console.log('not present');
    }
});
文件:


您可以使用
isPresent
确定页面中是否存在元素:

userCreationSuccessConfirmationMsg.isPresent().then(function (status) {
    if (status) {
        console.log('present');
    } else {
        console.log('not present');
    }
});
文件:


试试这个,我相信当一切顺利通过时,您实际上不需要登录:

expect(userCreationSuccessConfirmationMsg.isDisplayed()).toBeTruthy('Your message that should be printed when expectation is failed.')
Jasmine可以接受期望的可选消息,几乎所有匹配者都支持它

你们也可以看看我的库——它确实以智能的方式匹配了可见的元素——将在失败预期之前等待元素。当元素出现延迟时非常有用。欢迎您提出功能要求


试试这个,我相信当一切顺利通过时,您实际上不需要登录:

expect(userCreationSuccessConfirmationMsg.isDisplayed()).toBeTruthy('Your message that should be printed when expectation is failed.')
Jasmine可以接受期望的可选消息,几乎所有匹配者都支持它

你们也可以看看我的库——它确实以智能的方式匹配了可见的元素——将在失败预期之前等待元素。当元素出现延迟时非常有用。欢迎您提出功能要求


您的意思是isDisplayed()将返回文本而不是布尔响应吗?您的意思是isDisplayed()将返回文本而不是布尔响应吗?isPresent()将等待多长时间,或者等待元素出现的最长时间是多长。更确切地说,我的问题是,网页中有一个元素仅在页面启动时间30秒后才会显示,在这里,您的上述代码可以工作吗?方法
isPresent
不会等待。使用
浏览器。等待
等待条件。下面的代码是否会等待元素出现browser.wait(userCreationSuccessConfirmationMsg.isPresent().then(函数(状态){if(状态){console.log('present');}否则{console.log('notpresent');}}),5000);'isPresent()将等待多长时间,或者等待元素出现的最长时间是多少。更确切地说,我的问题是,网页中有一个元素仅在页面启动时间30秒后才会显示,在这里,您的上述代码可以工作吗?方法
isPresent
不会等待。使用
浏览器。等待
等待条件。下面的代码是否会等待元素出现browser.wait(userCreationSuccessConfirmationMsg.isPresent().then(函数(状态){if(状态){console.log('present');}否则{console.log('notpresent');}}),5000);'