【发布时间】:2017-10-27 10:38:40
【问题描述】:
我正在编写一个脚本来自动化我的表单提交。使用 webdriver 代码,我可以将数据添加到除 oi-select 之外的所有 html 输入。
我的 HTML DOM:
<oi-select class="multiSelect ng-pristine ng-empty ng-invalid ng-invalid-required multiple ng-touched" ng-if="to.key==null" oi-options="item for item in to.options" ng-model="model[options.key]" required="true" multiple="" id="formly_1_estoreMultiselect_category_0" name="formly_1_estoreMultiselect_category_0" formly-custom-validation="" ng-keyup="options.templateOptions['onKeyup'](model[options.key], options, this, $event)" ng-focus="options.templateOptions['onFocus'](model[options.key], options, this, $event)" ng-blur="options.templateOptions['onBlur'](model[options.key], options, this, $event)" type="estoreMultiselect" style="">
<div class="select-search">
<ul class="select-search-list">
<!---->
<li class="select-search-list-item select-search-list-item_input" ng-class="{'select-search-list-item_hide': inputHide}">
<input autocomplete="off" ng-model="query" ng-keyup="keyUp($event)" ng-keydown="keyDown($event)" class="ng-pristine ng-valid ng-empty ng-touched" placeholder="" style="">
</li>
<li class="select-search-list-item select-search-list-item_loader ng-hide" ng-show="showLoader">
</li>
</ul>
</div>
<div class="select-dropdown ng-hide" ng-show="isOpen">
<!---->
</div>
</oi-select>
这是我使用 Selenium WebDriver 获取它的代码:
driver.findElement(By.id("formly_1_estoreMultiselect_category_0")).clear();
driver.findElement(By.id("formly_1_estoreMultiselect_category_0")).sendKeys("Networking");
这是抛出的异常:
org.openqa.selenium.InvalidElementStateException:
Element must be user-editable in order to clear it.
如何向oi-select 添加值?
【问题讨论】:
-
错误是说您的元素不可编辑。如果它是一个输入标签,你可以做 sendkeys 所以尝试使用 xpath 像
//input[@class='ng-pristine ng-valid ng-empty ng-touched'] -
一些我如何能够弄清楚如何发送值但它的选择字段现在没有输入问题是在发送值之后..基于它执行 LDAP 搜索给出了一个值选项 i必须选择进入下拉列表。如果它是选择字段但我的是 oi-select 则非常容易...从 oi-select 选项中如何选择第一个值
-
如果可能的话,你能分享一下网址吗?如果您的选择是在发送文本后出现,请使用以下代码。并再次找到您所期望的第一个元素
标签: java angularjs selenium selenium-webdriver webdriver