Selenium python:找到并单击<;李>;从<;a>';s文本内部<;ul>;
我有点困在这里面了,我试着在表单中点击一个特定的li 然而,这个选择是基于a的文本/标题,这是在里面,我尝试了几件事,但没有一件是有效的,我有兴趣了解哪里是我的错,以及如何做得更好 这个表单由Angular提供支持,让我选择正确的邮政编码和城市名称(对人类来说很好,对刮擦来说很糟糕,哈哈)。因为我将不得不选择正确的一个与当前的邮政编码和多个城市,可以链接到一个邮政编码进行比较。(如果不清楚,在法国,一个邮政编码可以有多个城市,因此我必须选择正确的一个) 我在元素中使用了.send_keys()来获得要生成的结果(我的代码在下面的示例中) 以下是我得到的一个ul示例:Selenium python:找到并单击<;李>;从<;a>';s文本内部<;ul>;,selenium,selenium-webdriver,selenium-chromedriver,Selenium,Selenium Webdriver,Selenium Chromedriver,我有点困在这里面了,我试着在表单中点击一个特定的li 然而,这个选择是基于a的文本/标题,这是在里面,我尝试了几件事,但没有一件是有效的,我有兴趣了解哪里是我的错,以及如何做得更好 这个表单由Angular提供支持,让我选择正确的邮政编码和城市名称(对人类来说很好,对刮擦来说很糟糕,哈哈)。因为我将不得不选择正确的一个与当前的邮政编码和多个城市,可以链接到一个邮政编码进行比较。(如果不清楚,在法国,一个邮政编码可以有多个城市,因此我必须选择正确的一个) 我在元素中使用了.send_keys()来
<ul class="dropdown-menu ng-isolate-scope" ng-show="isOpen() && !moveInProgress" ng-style="{top: position().top+'px', left: position().left+'px'}" role="listbox" aria-hidden="false" uib-typeahead-popup="" id="typeahead-45-3695" matches="matches" active="activeIdx" select="select(activeIdx, evt)" move-in-progress="moveInProgress" query="query" position="position" assign-is-open="assignIsOpen(isOpen)" debounce="debounceUpdate" style="top: 34px; left: 15px;">
<!-- 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-45-3695-option-0" tabindex="0" style="">
<a href="" tabindex="-1" ng-bind-html="match.label | uibTypeaheadHighlight:query" ng-attr-title="{{match.label}}" class="ng-binding ng-scope" title="56400 - AURAY"><strong>56400</strong> - AURAY</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-45-3695-option-1" tabindex="0" style="">
<a href="" tabindex="-1" ng-bind-html="match.label | uibTypeaheadHighlight:query" ng-attr-title="{{match.label}}" class="ng-binding ng-scope" title="56400 - PLOUGOUMELEN"><strong>56400</strong> - PLOUGOUMELEN</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-45-3695-option-2" tabindex="0" style="">
<a href="" tabindex="-1" ng-bind-html="match.label | uibTypeaheadHighlight:query" ng-attr-title="{{match.label}}" class="ng-binding ng-scope" title="56400 - BONO"><strong>56400</strong> - BONO</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-45-3695-option-3" tabindex="0" style="">
<a href="" tabindex="-1" ng-bind-html="match.label | uibTypeaheadHighlight:query" ng-attr-title="{{match.label}}" class="ng-binding ng-scope" title="56400 - PLOEMEL"><strong>56400</strong> - PLOEMEL</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-45-3695-option-4" tabindex="0">
<a href="" tabindex="-1" ng-bind-html="match.label | uibTypeaheadHighlight:query" ng-attr-title="{{match.label}}" class="ng-binding ng-scope" title="56400 - BRECH"><strong>56400</strong> - BRECH</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-45-3695-option-5" tabindex="0">
<a href="" tabindex="-1" ng-bind-html="match.label | uibTypeaheadHighlight:query" ng-attr-title="{{match.label}}" class="ng-binding ng-scope" title="56400 - PLUMERGAT"><strong>56400</strong> - PLUMERGAT</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-45-3695-option-6" tabindex="0">
<a href="" tabindex="-1" ng-bind-html="match.label | uibTypeaheadHighlight:query" ng-attr-title="{{match.label}}" class="ng-binding ng-scope" title="56400 - PLUNERET"><strong>56400</strong> - PLUNERET</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-45-3695-option-7" tabindex="0">
<a href="" tabindex="-1" ng-bind-html="match.label | uibTypeaheadHighlight:query" ng-attr-title="{{match.label}}" class="ng-binding ng-scope" title="56400 - SAINTE-ANNE-D'AURAY"><strong>56400</strong> - SAINTE-ANNE-D'AURAY</a>
</li><!-- end ngRepeat: match in matches track by $index -->
</ul>
及
我目前没有检查哪一个li是正确的,我只尝试选择当前标题正确的一个
如果你有任何想法
谢谢大家 您可以尝试等待列表中的所需选项:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver.find_element_by_name("postalCode").send_keys("56400")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, '56400 - AURAY'))).click()
driver.find_element_by_xpath(f"//ul[@ng-show=\"isOpen() && !moveInProgress\" and starts-with(@id, 'li_'][contains(text(),'56400 - AURAY')]").click()
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver.find_element_by_name("postalCode").send_keys("56400")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, '56400 - AURAY'))).click()