无法使用selenium webdriver在时间控制器中输入时间

问题描述 投票:0回答:1

HTML代码:

<mat-form-field _ngcontent-c18="" class="mat-input-container mat-form-field ng-tns-c7-23 mat-form-field-type-mat-input mat-form-field-can-float mat-form-field-should-float mat-primary ng-untouched ng-pristine ng-invalid"><div class="mat-input-wrapper mat-form-field-wrapper"><div class="mat-input-flex mat-form-field-flex"><!--bindings={
  "ng-reflect-ng-if": "0"
}--><div class="mat-input-infix mat-form-field-infix">
              <input _ngcontent-c18="" class="mat-input-element mat-form-field-autofill-control ng-untouched ng-pristine ng-invalid" formcontrolname="scheduleFromTimeControl" id="startTime" matinput="" placeholder="Start Time" type="time" ng-reflect-name="scheduleFromTimeControl" ng-reflect-id="startTime" ng-reflect-placeholder="Start Time" ng-reflect-type="time" aria-invalid="false">
            <span class="mat-input-placeholder-wrapper mat-form-field-placeholder-wrapper"><!--bindings={
  "ng-reflect-ng-if": "true"
}--><label class="mat-input-placeholder mat-form-field-placeholder ng-tns-c7-23 ng-star-inserted" for="startTime" aria-owns="startTime">Start Time <!--bindings={
  "ng-reflect-ng-if": "false"
}--></label></span></div><!--bindings={
  "ng-reflect-ng-if": "0"
}--></div><div class="mat-input-underline mat-form-field-underline"><span class="mat-input-ripple mat-form-field-ripple"></span></div><div class="mat-input-subscript-wrapper mat-form-field-subscript-wrapper" ng-reflect-ng-switch="hint"><!--bindings={
  "ng-reflect-ng-switch-case": "error"
}--><!--bindings={
  "ng-reflect-ng-switch-case": "hint"
}--><div class="mat-input-hint-wrapper mat-form-field-hint-wrapper ng-tns-c7-23 ng-trigger ng-trigger-transitionMessages ng-star-inserted"><!--bindings={
  "ng-reflect-ng-if": ""
}--><div class="mat-input-hint-spacer mat-form-field-hint-spacer"></div></div></div></div></mat-form-field>        

我无法使用.sendKeys输入时间控制器

我在.SendKeys方法中使用了以下组合:

WebDriverUtils.getWebDriver().findElement(By.id(starttime)).sendKeys("Keyss" +Keys.TAB);
WebDriverUtils.getWebDriver().findElement(By.id(starttime)).sendKeys("12:01 AM");
WebDriverUtils.getWebDriver().findElement(By.id(starttime)).sendKeys("1201 AM");
WebDriverUtils.getWebDriver().findElement(By.id(starttime)).sendKeys("10");

Inspect元素看起来如下:

<input _ngcontent-c18="" class="mat-input-element mat-form-field-autofill-control ng-invalid ng-dirty ng-touched" formcontrolname="scheduleFromTimeControl" id="startTime" matinput="" placeholder="Start Time" ng-reflect-name="scheduleFromTimeControl" ng-reflect-id="startTime" ng-reflect-placeholder="Start Time" ng-reflect-type="time" aria-invalid="true" ng-reflect-model="" type="time">

请不是我能够选择开始时间,但无法输入时间...请找到控制快照 snapshot

angularjs selenium-webdriver ui-automation browser-automation
1个回答
0
投票

我得到了解决方案,我使用的格式不正确。正确的格式如下:

    WebDriverUtils.getWebDriver().findElement(By.id(starttime)).sendKeys("10:10");
© www.soinside.com 2019 - 2024. All rights reserved.