我正在尝试自动测试我添加了ng-tags-input的网页。我在使用 selenium 网络驱动程序将标签添加到 ng-tags 输入时遇到困难。Selenium找到元素,但sendKeys()函数不向其添加文本。
硒代码(v. 2.49.0):
driver.findElement(By.id("tags")).sendKeys("test, one, two, three");
.HTML:
<tags-input ng-model="tempTags" id="tags" ng-model-options="{ getterSetter: true }" on-tag-added="convertToTagString()" on-tag-removed="convertToTagString()"></tags-input>
最终的 HTML:
<tags-input ng-model="tempTags" id="tags" ng-model-options="{ getterSetter: true }" on-tag-added="convertToTagString()" on-tag-removed="convertToTagString()" class="ng-pristine ng-valid ng-isolate-scope ng-valid-max-tags ng-valid-min-tags ng-valid-leftover-text ng-touched">
<div class="host" tabindex="-1" ng-click="eventHandlers.host.click()" ti-transclude-append="">
<div class="tags" ng-class="{focused: hasFocus}">
<ul class="tag-list">
<!-- ngRepeat: tag in tagList.items track by track(tag) -->
</ul>
<input class="input ng-valid ng-touched ng-dirty ng-valid-parse" autocomplete="off" ng-model="newTag.text" ng-model-options="{getterSetter: true}" ng-keydown="eventHandlers.input.keydown($event)" ng-focus="eventHandlers.input.focus($event)" ng-blur="eventHandlers.input.blur($event)" ng-paste="eventHandlers.input.paste($event)" ng-trim="false" ng-class="{'invalid-tag': newTag.invalid}" ng-disabled="disabled" ti-bind-attrs="{type: options.type, placeholder: options.placeholder, tabindex: options.tabindex, spellcheck: options.spellcheck}" ti-autosize="" type="text" placeholder="Add a tag" spellcheck="true" style="width: 69px;"><span class="input" style="visibility: hidden; width: auto; white-space: pre; display: none;">Add a tag</span>
</div>
</div>
</tags-input>
SendKeys() 到 input(不是 ng-tags-input)的 xpath 工作。
driver.findElement(By.xpath("//*[@id="tags"]/div/div/input")).sendKeys("test, five");