<p>该页使用的自定义选择组件不能与selenium<code>Select</code>类交互。Select类只能用于默认的<a href="https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select" rel="nofollow noreferrer">html select component</a>。你知道吗</p>
<p>我们必须像手动步骤那样自动化</p>
<ol>
<li>单击输入测试框</li>
<li>等待下拉列表出现。你知道吗</li>
<li>单击下拉列表中显示的相应值。你知道吗</li>
</ol>
<p>在您的例子中,我们可以使用title属性或通过选择列表中锚定标记的显示值来选择下拉列表。你知道吗</p>
<pre><code> <a title="Territories">Territories</a>
</code></pre>
<hr/>
<pre><code>def select_by_title(value):
# click the input component
driver.find_element_by_css_selector('input#SearchLocationPicker"]').send_keys(value)
# Wait for the value to appear in dropdown.
wait = WebDriverWait(driver, 60)
element = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '#SearchLocationPicker~div>ul>li>a[title="'+value+'"')))
# Click the element
element.click()
</code></pre>
<p>或者</p>
<pre><code>def select_by_display_value(value):
driver.find_element_by_css_selector('#SearchLocationPicker"]').send_keys(value)
wait = WebDriverWait(driver, 60)
element = wait.until(EC.visibility_of_element_located((By.XPATH, '//input[@id="SearchLocationPicker"]/following-sibling::div/ul/li/a[text() = "'+value+'"]')))
element.click()
</code></pre>