Protractor sendKeys()只传递部分值,或者无法在日期字段中输入日期输入

Protractor sendKeys()只传递部分值,或者无法在日期字段中输入日期输入,protractor,Protractor,我使用的是量角器版本5.2.2。我的项目中有两个日期字段。我使用了以下代码输入日期 element(by.xpath("//*[@id='divContractInfo']/div[1]/div[2]/div/my-date-picker/div/div/input")).sendKeys("01-02-2019"); browser.sleep(5000); element(by.xpath("//*[@id='divContractInfo']/div[1]/div[3]/div/my-da

我使用的是量角器版本5.2.2。我的项目中有两个日期字段。我使用了以下代码输入日期

element(by.xpath("//*[@id='divContractInfo']/div[1]/div[2]/div/my-date-picker/div/div/input")).sendKeys("01-02-2019");
browser.sleep(5000);
element(by.xpath("//*[@id='divContractInfo']/div[1]/div[3]/div/my-date-picker/div/div/input")).sendKeys("12-02-2020");
使用此代码,只有输入的第一个字符被输入到第一个日期字段中。但第二个日期输入被完全输入到第二个日期字段中

当我使用另一个代码(如下所示)时,日期值会完全输入到日期输入框中。但在表单中输入其余字段时,会出现验证错误,即“date is required”。解决方法是什么

var inputEle = element(by.xpath("//*[@id='divContractInfo']/div[1]/div[2]/div/my-date-picker/div/div/input"));
var inputValue = 04-12-2020;
inputEle.click();
browser.executeScript('arguments[0].value=arguments[1]', 
                  inputEle.getWebElement(), 
                  inputValue); 
UI代码(角度)如下所示

<div _ngcontent-c6="" class="frx-form-field-container">
  <label _ngcontent-c6="" class="frx-form-label">Effective Date:</label>
    <div _ngcontent-c6="" class="frx-form-input-field-container-small">
      <my-date-picker _ngcontent-c6="" class="frx-mydatepicker-field ng-pristine ng-valid ng-touched" formcontrolname="effectiveDate" frxconfirmequalvalidator="terminationDate" name="effectiveDate" ng-reflect-frx-confirm-equal-validator="terminationDate" ng-reflect-options="[object Object]" ng-reflect-name="effectiveDate" ng-reflect-frx-validate="[object Object]" ng-reflect-validation-message="" ng-reflect-status="false"><div class="mydp" ng-reflect-ng-style="[object Object]" style="width: 145px;"><!--bindings={
       "ng-reflect-ng-if": "true"                 
       }--><div class="selectiongroup"><!--bindings={
      "ng-reflect-ng-if": "true"
      }--><input autocomplete="off" autocorrect="off" class="selection ng-pristine ng-valid ng-touched" ngtype="text" spellcheck="false" ng-reflect-klass="selection" ng-reflect-ng-class="[object Object]" ng-reflect-ng-style="[object Object]" ng-reflect-is-disabled="false" ng-reflect-model="06-24-2018" aria-label="Date input field" placeholder="" style="height: 28px; font-size: 14px;"><div class="selbtngroup" style="height: 28px;"><!--bindings={
      "ng-reflect-ng-if": "false"
      }--> <!--bindings={
      "ng-reflect-ng-if": "false"
      }--> <!--bindings={
     "ng-reflect-ng-if": "true"
     }--><button class="btnclear btnclearenabled" type="button" ng-reflect-klass="btnclear" ng-reflect-ng-class="[object Object]" aria-label="Clear Date"><span class="mydpicon icon-mydpremove"></span></button> <button class="btnpicker btnpickerenabled" type="button" ng-reflect-klass="btnpicker" ng-reflect-ng-class="[object Object]" aria-label="Open Calendar"><span class="mydpicon icon-mydpcalendar"></span></button></div></div><!--bindings={
     "ng-reflect-ng-if": "false"
     }--></div></my-date-picker>
   </div>
</div>
<div _ngcontent-c6="" class="frx-form-field-container">
  <label _ngcontent-c6="" class="frx-form-label">Termination Date:</label>
    <div _ngcontent-c6="" class="frx-form-input-field-container-small">
      <my-date-picker _ngcontent-c6="" class="frx-mydatepicker-field ng-untouched ng-pristine ng-valid" formcontrolname="terminationDate" frxconfirmequalvalidator="effectiveDate" name="terminationDate" ng-reflect-frx-confirm-equal-validator="effectiveDate" ng-reflect-options="[object Object]" ng-reflect-name="terminationDate" ng-reflect-frx-validate="[object Object]" ng-reflect-validation-message="" ng-reflect-status="false"><div class="mydp" ng-reflect-ng-style="[object Object]" style="width: 145px;"><!--bindings={
      "ng-reflect-ng-if": "true"
      }--><div class="selectiongroup"><!--bindings={
      "ng-reflect-ng-if": "true"
      }--><input autocomplete="off" autocorrect="off" class="selection ng-untouched ng-pristine ng-valid" ngtype="text" spellcheck="false" ng-reflect-klass="selection" ng-reflect-ng-class="[object Object]" ng-reflect-ng-style="[object Object]" ng-reflect-is-disabled="false" ng-reflect-model="06-24-2019" aria-label="Date input field" placeholder="" style="height: 28px; font-size: 14px;"><div class="selbtngroup" style="height: 28px;"><!--bindings={
     "ng-reflect-ng-if": "false"
     }--> <!--bindings={
    "ng-reflect-ng-if": "false"
     }--> <!--bindings={
    "ng-reflect-ng-if": "true"
    }--><button class="btnclear btnclearenabled" type="button" ng-reflect-klass="btnclear" ng-reflect-ng-class="[object Object]" aria-label="Clear Date"><span class="mydpicon icon-mydpremove"></span></button> <button class="btnpicker btnpickerenabled" type="button" ng-reflect-klass="btnpicker" ng-reflect-ng-class="[object Object]" aria-label="Open Calendar"><span class="mydpicon icon-mydpcalendar"></span></button></div></div><!--bindings={
   "ng-reflect-ng-if": "false"
   }--></div></my-date-picker>
 </div>
</div>

生效日期:
终止日期:

我不理解第一个日期输入未完全输入的原因。提前感谢。

两个日期选择器的UI代码似乎相同,因此元素选择正确。在输入第一个日期输入之前,请尝试添加
sleep

在输入第一个日期输入之前,我尝试了8,10,15毫秒,但没有帮助。在发送值之前,请在日期选择器文本框内尝试
单击()<代码>元素(按.xpath(“/*[@id='divconstractinfo']/div[1]/div[2]/div/my date picker/div/div/input”)。单击();浏览器。睡眠(3000);元素(by.xpath(“/*[@id='divconstractinfo']/div[1]/div[2]/div/my date picker/div/div/input”)).sendKeys(“01-02-2019”)我已尝试单击()并等待发送值。但这也没有帮助。请使用
browser.executeScript(“参数[0].setAttribute('value','01-02-2019')”,元素(by.xpath(“/*[@id='divconstructInfo']/div[1]/div[2]/div/my date picker/div/div/div/input”)
而不是
元素(按.xpath(“/*[@id='divconstractinfo']/div[1]/div[2]/div/my date picker/div/div/input”))。sendKeys(“01-02-2019”)谢谢你的努力。但是上面的代码对我也不起作用。我已经更新了这个问题。在这个方法中,我能够将输入完全输入到字段中。但是它会给出验证错误。有解决方案吗?提前谢谢。如果你这样做,它是否起作用:element(by.xpath(“/*[@id='divconstractinfo']/div[1]/div[2]/div/my date picker/div/div/input”)).sendKeys(“0”);然后是元素(by.xpath(“/*[@id='divconstractinfo']/div[1]/div[2]/div/my date picker/div/div/input”)).sendKeys(“1”);等等?如果是这样,则可能是键发送速度的计时问题。感谢您的努力。我可以通过将其作为节/字符传递来成功输入值。在第一步中,它仅检测第一个字符,因此在第二步中,我已经把剩下的角色全部传给了这个领域。为什么会这样?看吧,但他们声称这是固定的