C#硒找不到输入

时间:2018-07-16 19:52:31

标签: c# html selenium

我正在努力寻找html中的输入字段,我可以使用以下代码填充每个输入字段:

public async Task FillElementAsync(By by, string arg)
        {
            WebDriverWait wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(20));
            IWebElement myDynamicElement = wait.Until<IWebElement>((d) =>
            {
                return d.FindElement(by);
            });
            myDynamicElement.SendKeys(arg);
        }

但是当我尝试填写此输入时,我无法集中该元素:

<span class="center-block">
   <sprd-label-input model="">
      <div class="label-input-wrapper" ng-class="{'active': focused || !!inputValue.length || !!modelValue.length || placeholderExists, 'filled': inputValue.length || modelValue.length}" ng-transclude="">
         <div ng-model="idea.getCurrentTranslation().tags" sprd-validate-tags="idea" blacklist-result="tagsBlacklist" name="tags" class="ng-pristine ng-untouched ng-valid ng-not-empty ng-valid-tags ng-valid-blacklist"></div>
         <label for="design-detail-tags" class="text-medium-grey">Stichwörter</label>
         <!---->
         <sprd-tag-input ng-model="idea.getCurrentTranslation().tags" idea-name="idea.getCurrentTranslation().name" display-tags-left="true" display-related-tags="true" display-error-text="form.$error.tags" blacklist-result="tagsBlacklist" id="input-design-tags" name="designTags" class="ng-pristine ng-untouched ng-valid ng-not-empty">
            <div class="clearfix">
               <!---->
               <div class="tag-input-container form-control clearfix" focus-input-on-click="" remove-on-backspace="ngModel">
                  <!---->
                  <input ng-model="TagInputCtrl.tagInput" uib-typeahead="tagSuggestion for tagSuggestion in TagInputCtrl.getTagSuggestions($viewValue)" class="pull-left ng-pristine ng-untouched ng-valid ng-empty" select-on-comma="" select-on-whitespace="" select-on-blur="" typeahead-focus-first="false" tag-select="TagInputCtrl.onEnter" tag-select-model="ngModel" sprd-max-input-length="50" ng-show="ngModel.length < TagInputCtrl.validatorOptions.tags.max" aria-autocomplete="list" aria-expanded="false" aria-owns="typeahead-2871-1170" type="text">
                  <ul class="dropdown-menu ng-hide" ng-show="isOpen() &amp;&amp; !moveInProgress" ng-style="{top: position().top+'px', left: position().left+'px'}" role="listbox" aria-hidden="true" uib-typeahead-popup="" id="typeahead-2871-1170" matches="matches" active="activeIdx" select="select(activeIdx, evt)" move-in-progress="moveInProgress" query="query" position="position" assign-is-open="assignIsOpen(isOpen)" debounce="debounceUpdate" style="">
                     <!---->
                  </ul>
               </div>
               <!---->
               <p ng-if="displayTagsLeft" class="pull-right">
                  <small class="design-tags-left">noch 25 Stichwörter</small>
               </p>
               <!---->
               <!---->
               <div ng-if="displayRelatedTags" class="form-group clearfix tag-input-related-tags ng-hide" ng-show="TagInputCtrl.relatedTags.length > 0">
                  <p class="label-description pull-left" style="margin-top: 3px;">Vorschläge für Stichwörter:</p>
                  <ul class="list-inline related-tags-list pull-left">
                     <!---->
                  </ul>
               </div>
               <!---->
            </div>
         </sprd-tag-input>
      </div>
   </sprd-label-input>
</span>

我试图通过ClassName(“标签输入容器”),ID(“输入设计标签”)和名称(“ designTags”)查找元素。所以我的问题是为什么,除了自动完成功能之外,这种输入类型还有什么特别之处?

1 个答案:

答案 0 :(得分:1)

您应该确保将键发送到input元素,而不是sprd-tag-input元素。

FillElementAsync(By.CssSelector("#input-design-tags input"), "test")

请注意,您可能需要先单击sprd-tag-input元素以激活输入。