2

我正在尝试自动测试添加了 ng-tags-input 的网页。我在使用 selenium webdriver 向 ng-tags-input 添加标签时遇到了困难。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>
4

1 回答 1

1

SendKeys() 到输入(不是 ng-tags-input)的 xpath 工作。

driver.findElement(By.xpath("//*[@id=\"tags\"]/div/div/input")).sendKeys("test, five");
于 2016-02-04T08:06:44.373 回答