Selecting angular-ui date-picker value from the ca

2019-02-20 13:56发布

问题:

My datepicker structure looks like:

<button type="button" class="date-picker-item">
 <span>1</span>
</button>
<button type="button" class="date-picker-item">
 <span>2</span>
</button>

etc..

I am trying to use by.cssContainingText from the protractor api.

element.all(by.cssContainingText('.date-picker-item > span', day))

but its not selecting it at the minute. Do I need to target this a different way?

Thanks a lot in advance.

回答1:

In one of my project i wrote function like this:

elementDate: function(inArray,object){
    var day = inArray.day.toString();
    var cYear = new Date();
    var cYear = cYear.getFullYear();
    var year = inArray.year;
    var month = inArray.month;
    object.click();
    element(by.css('.btn.btn-sm.btn-danger.uib-clear.ng-binding')).click().then(function(){
      return  object.click()
    });
    element(by.css('button[ng-click="toggleMode()"]')).click();
    if(cYear > year){
      for(var i = cYear; i > year; i--){

        object.element(by.css('.btn.btn-default.btn-sm.pull-left.uib-left')).click();
      };
    }
    else if (cYear < year) {

      for(var i = cYear; i < year; i++){
        object.element(by.css('.btn.btn-default.btn-sm.pull-right.uib-right')).click();
      };
    }
    else{
    }
    element(by.cssContainingText('.btn.btn-default', month)).click();
    element(by.cssContainingText('.uib-day .btn.btn-default.btn-sm', day)).click();
    return this;
  },

It takes dataPicker element (for example if you would have 2 data pickers one would be name="DatePick1" second name="DatePick2" as element name) and array of date, i think you should only change by.css elements for your project, i recommend to use fireBug to do so