Protractor if ,else with (expect(condition))

天大地大妈咪最大 提交于 2019-12-08 09:50:15

问题


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();
}

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


回答1:


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();
});



回答2:


I don't know how long is your list, but it seems that you can simplify your code. How about use:

element(by.model('trt_model')).get(last).click();

instead of whole if statement?



来源:https://stackoverflow.com/questions/44362880/protractor-if-else-with-expectcondition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!