Ich versuche ein Element aus einer Autosuggestion-Liste mithilfe von Xpath zu finden, bekomme aber InvalidSelectorException. Unten ist mein Code: -Das Element kann nicht mit Hilfe von XPath aus der Dropdown-Liste "Automatisch vorschlagen" gefunden werden.
WebDriverWait wait=new WebDriverWait(driver, 10);
driver.findElement(By.xpath(".//*[@id='EngagementCode']")).sendKeys("111");
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//[@id='typeahead-5-5946-option-0']/a"))).click();
Bitte schlagen Sie auch vor Wie kann ich es mit anderen Methoden finden, wenn möglich.
<ul id="typeahead-5-5946" class="dropdown-menu ng-isolate-scope" ng-show="isOpen() && !moveInProgress" ng-style="{top: position().top+'px', left: position().left+'px'}" style="display: block; top: 34px; left: 15px;" role="listbox" aria-hidden="false" typeahead-popup="" matches="matches" active="activeIdx" select="select(activeIdx)" move-in-progress="moveInProgress" query="query" position="position">
<!-- ngRepeat: match in matches track by $index -->
<li id="typeahead-5-5946-option-0" class="ng-scope active" ng-repeat="match in matches track by $index" ng-class="{active: isActive($index) }" ng-mouseenter="selectActive($index)" ng-click="selectMatch($index)" role="option">
<a class="ng-binding ng-scope" href="" tabindex="-1" ng-bind-html="match.label | typeaheadHighlight:query">
xxx
<strong>111</strong>
x - xxx services_xxx
</a>
</li>
<!-- end ngRepeat: match in matches track by $index -->
Ihre XPath ok aussieht. Überprüfen Sie nur, ob der Selektor mehrere Elemente zurückgibt –
Entschuldigung, aber ich bin neu dazu Wie soll ich das überprüfen? –
https://www.freeformatter.com/xpat-tester.html. Sie können Ihre XPath-Gültigkeit hier überprüfen. –