我想使用Selenium在搜索栏中输入城市,街区或街道,然后在建议栏中选择弹出的第一个选项,条件是该类别与之前所述的类别相同( ,邻里或街道)。 html在下面恢复:
<label class="autocomplete__list-title js-autocomplete-title"> Streets </label>
<ul class="autocomplete__list">
<li class="autocomplete__item js-autocomplete-suggestion" data-type="street" title="Rua Atibaia, Vila Valparaiso, Santo André - SP" data-index="0" data-active="">
<span class="js-location-name">Rua Atibaia, Vila Valparaiso, Santo André - </span><span class="js-location-uf">SP</span>
</li>
</ul>
<label class="autocomplete__list-title js-autocomplete-title"> Cities </label>
<ul class="autocomplete__list">
<li class="autocomplete__item js-autocomplete-suggestion" data-type="city" title="Atibaia - SP" data-index="0">
<span class="js-location-name">Atibaia - </span><span class="js-location-uf">SP</span>
</li>
</ul>
<label class="autocomplete__list-title js-autocomplete-title"> Neighbourhoods </label>
<ul class="autocomplete__list">
<li class="autocomplete__item js-autocomplete-suggestion" data-type="neighborhood" title="Atibaia Jardim, Atibaia - SP" data-index="0">
<span class="js-location-name">Atibaia Jardim, Atibaia - </span><span class="js-location-uf">SP</span>
</li>
当前,我有以下代码:
variable1 = 'city' #here we choose city, neighbourhood or
street
id_name = 'São Paulo' #Here is what I want to search
element = driver.find_element_by_xpath('//*[@id="filter-location-search-
input"]')
element.send_keys(id_name)
time.sleep(5)
但是我很难根据搜索内容在建议列表中选择一个选项