【问题标题】:Protractor: cannot access input element量角器:无法访问输入元素
【发布时间】:2018-05-29 13:32:25
【问题描述】:

Chrome 浏览器中的“sendKeys()”方法有问题。 我有这样的页面:

一个视图看起来像:

<td class="ng-binding">
<div class="b-combobox ps-list-drop-single-autocomplete ng-isolate-scope ng-pristine ng-required ng-invalid ng-invalid-required" required="required" placeholder="Еnто placeholder деTка!" name="autocomplete1" text="autocomplete.text" style="width: 200px; padding-right: 16px;" selected="selected" options="{allowUserValue: true}">
    <div data-for="drop-single-autocomplete" ps-link-element="elements.input_wrap" class="b-combobox__autocomplete b-combobox__value_full_size">
        <input ps-link-element="elements.input_offer" tabindex="-1" readonly="" class="b-combobox__input b-combobox__placeholder" type="text">
        <input ps-link-element="elements.input_editable" on-link-element="onLinkInputEditable()" ng-readonly="states.readonly || states.disabled" class="b-combobox__input" type="text" ps-attr="{maxlength: +maxlength >= 0 &amp;&amp; maxlength, tabindex:states.tabIndex}" tabindex="0">
    </div>
    <div class="b-combobox__buttons ng-scope" ng-if="options.isDropButton || options.isActionVisible || options.showDropDownButton || (options.allowUserValue &amp;&amp; options.isDropSingleAutocomplete)" ps-link-element="elements.buttons" on-link-element="onLinkButtons()" unselectable="on">
        <a class="b-button_arrow b-button ng-scope" tabindex="-1" ng-if="options.showDropDownButton &amp;&amp; !options.isDropButton" ps-attr="{main: states.main, disabled: states.disabled}" ps-mousedown="onShowListButton($event)" unselectable="on"></a>
    </div>
</div>
    "
              Значение из списка: (), произвольное зхначение: ()
    "

我想向这个字段发送 Key.DOWN。或者只是写一些文字。但是当我尝试这样做时,我遇到了错误:“无法聚焦元素”。当我尝试单击()此元素时,它工作正常。 我尝试将browser.ignoreSynchronization = true; 添加到我的代码中,但没有帮助。

【问题讨论】:

  • 你能显示这个下拉列表的完整 HTML 吗?为什么 деТка? :)
  • @alecxe 好的。非常奇怪的人给我写了这些表格。有时我不明白他的意思=)

标签: angularjs jasmine protractor


【解决方案1】:

我觉得你需要先点击元素进入可编辑模式,然后在input中输入文字:

var dropdown = element(by.name("autocomplete1"));
dropdown.click();

var input = dropdown.element(by.css('input[ps-link-element="elements.input_editable"]'));
input.sendKeys("test");

这仍然是一个猜测/在黑暗中拍摄,因为我无法重现该问题。

【讨论】:

  • 呃!你是我的英雄!谢谢!
猜你喜欢
  • 2021-07-08
  • 1970-01-01
  • 1970-01-01
  • 2020-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多