我无法使用Java的Selenium从动态搜索框中选择元素。

huangapple 未分类评论49阅读模式
英文:

I am not able to select an element from dynamic search box using selenium with java

问题

动态搜索列表位于一个 ul 标签下,其中包含不同的 li 标签。在 li 标签下,有两个子元素,其中 span 标签包含了值。

<ul class="dropdown-menu ng-isolate-scope" ng-show="isOpen() &amp;amp;&amp;amp; !moveInProgress" ng-style="{top: position().top+'px', left: position().left+'px'}" role="listbox" aria-hidden="false" uib-typeahead-popup="" id="typeahead-60-892" matches="matches" active="activeIdx" select="select(activeIdx, evt)" move-in-progress="moveInProgress" query="query" position="position" assign-is-open="assignIsOpen(isOpen)" debounce="debounceUpdate" template-url="postlogin/admin/clientProvision/typeAheadResultsTemplate.html" style="top: 34px; left: 10px;">
    <!-- ngRepeat: match in matches track by $index -->
    <li class="uib-typeahead-match ng-scope active" ng-repeat="match in matches track by $index" ng-class="{active: isActive($index) }" ng-mouseenter="selectActive($index)" ng-click="selectMatch($index, $event)" role="option" id="typeahead-60-892-option-0" tabindex="0" style="">
        <a class="law-firm-office-name-search-result ng-scope">
            <span ng-bind-html="match.label | uibTypeaheadHighlight:query" class="ng-binding"><strong>**Baker Tilly Beers &amp;amp;</strong> Cutler, PLLC, Tysons Corner</span>
        </a>
    </li><!-- end ngRepeat: match in matches track by $index -->
    <li class="uib-typeahead-match ng-scope" ng-repeat="match in matches track by $index" ng-class="{active: isActive($index) }" ng-mouseenter="selectActive($index)" ng-click="selectMatch($index, $event)" role="option" id="typeahead-60-892-option-1" tabindex="0">
        <a class="law-firm-office-name-search-result ng-scope">
            <span ng-bind-html="match.label | uibTypeaheadHighlight:query" class="ng-binding"><strong>**Baker Tilly Beers &amp;amp;</strong> Cutler, PLLC, Vienna VA</span>
        </a>
    </li><!-- end ngRepeat: match in matches track by $index -->
</ul>

我了解你的方法,但我无法创建能够获取 Web 元素列表的 XPath,然后我可以将其与我想要发送的文本进行比较。

英文:

Dynamic search list is under one ul tag and it has different li tags . Under li tags, it has two childs in which span tag contains the value.

&lt;ul class=&quot;dropdown-menu ng-isolate-scope&quot; ng-show=&quot;isOpen() &amp;amp;&amp;amp; !moveInProgress&quot; ng-style=&quot;{top: position().top+&#39;px&#39;, left: position().left+&#39;px&#39;}&quot; role=&quot;listbox&quot; aria-hidden=&quot;false&quot; uib-typeahead-popup=&quot;&quot; id=&quot;typeahead-60-892&quot; matches=&quot;matches&quot; active=&quot;activeIdx&quot; select=&quot;select(activeIdx, evt)&quot; move-in-progress=&quot;moveInProgress&quot; query=&quot;query&quot; position=&quot;position&quot; assign-is-open=&quot;assignIsOpen(isOpen)&quot; debounce=&quot;debounceUpdate&quot; template-url=&quot;postlogin/admin/clientProvision/typeAheadResultsTemplate.html&quot; style=&quot;top: 34px; left: 10px;&quot;&gt;
    &lt;!-- ngRepeat: match in matches track by $index --&gt;
&lt;li class=&quot;uib-typeahead-match ng-scope active&quot; ng-repeat=&quot;match in matches track by $index&quot; ng-class=&quot;{active: isActive($index) }&quot; ng-mouseenter=&quot;selectActive($index)&quot; ng-click=&quot;selectMatch($index, $event)&quot; role=&quot;option&quot; id=&quot;typeahead-60-892-option-0&quot; tabindex=&quot;0&quot; style=&quot;&quot;&gt;

        &lt;a class=&quot;law-firm-office-name-search-result ng-scope&quot;&gt;
    &lt;span ng-bind-html=&quot;match.label | uibTypeaheadHighlight:query&quot; class=&quot;ng-binding&quot;&gt;&lt;strong&gt;**Baker Tilly Beers &amp;amp;&lt;/strong&gt; Cutler, PLLC, Tysons Corner**&lt;/span&gt;
&lt;/a&gt;
    &lt;/li&gt;&lt;!-- end ngRepeat: match in ma``tches track by $index --&gt;&lt;li class=&quot;uib-typeahead-match ng-scope&quot; ng-repeat=&quot;match in matches track by $index&quot; ng-class=&quot;{active: isActive($index) }&quot; ng-mouseenter=&quot;selectActive($index)&quot; ng-click=&quot;selectMatch($index, $event)&quot; role=&quot;option&quot; id=&quot;typeahead-60-892-option-1&quot; tabindex=&quot;0&quot;&gt;
        &lt;a class=&quot;law-firm-office-name-search-result ng-scope&quot;&gt;
    &lt;span ng-bind-html=&quot;match.label | uibTypeaheadHighlight:query&quot; class=&quot;ng-binding&quot;&gt;&lt;strong&gt;**Baker Tilly Beers &amp;amp;&lt;/strong&gt; Cutler, PLLC, Vienna VA**&lt;/span&gt;
&lt;/a&gt;
    &lt;/li&gt;&lt;!-- end ngRepeat: match in matches track by $index --&gt;
&lt;/ul&gt;

I know the approach but I am not able to create the xpath so that I can get a list of Web Elements and then I can compare with the text I want to send

huangapple
  • 本文由 发表于 2020年5月3日 19:28:45
  • 转载请务必保留本文链接:https://java.coder-hub.com/61573695.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定