量角器如果(否则(期望(条件))否则 [英] Protractor if ,else with (expect(condition))

查看:238
本文介绍了量角器如果(否则(期望(条件))否则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的脚本中,我需要包含if和else语句,这是代码

in my script i need to include if and else statement,here is the code

if((element(by.model('trt_model')).all(by.tagName('option')).get(0).getText()).toEqual('Select Contract'))
{
    element(by.model('trt_model')).get(1).click();
}
else
{
    element(by.model('trt_model')).get(0).click();
}

如果期望条件失败,我希望脚本执行else部分,但这不起作用. 当预期条件失败时,脚本不执行else部分

if the expect condition fails , i want the script to execute the else part, but this is not working. when expect condition fails,the script is not executing the else part

请提出如何解决此问题的建议 谢谢

kindly suggest how this can be resolved Thank you

推荐答案

我简化了您的代码并粘贴到下面.你可以试试这个.如果您遇到以下代码有任何错误,请告诉我.希望它能工作.

I have simplified your code and pasted below. You can try this one. Please let me know if you face any error with below code. Hope it will work.

element(by.model('trt_model')).all(by.tagName('option')).get(0).getText  
 ()).then(function(text){
        if(text==='Select Contract')
            element(by.model('trt_model')).get(1).click();
       else
           element(by.model('trt_model')).get(0).click();
});

这篇关于量角器如果(否则(期望(条件))否则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆