如何在Python中使用Selenium处理自动建议下拉列表



我正试图通过python脚本填写此表单:https://reassurez-moi.fr/simulation-tarifaire-assurance-habitation?homeType=1

但不幸的是,我不知道如何在Python中使用Selenium处理Auto Suggestion Dropdown。

事实上,当我写街道名称时,我想选择下拉列表中的第一个元素(法语:"Adresse du bien"(。

你能告诉我如何制作一个允许我这样做的python脚本吗?

提前谢谢。

下面的代码显示了我到目前为止所做的工作,但它不允许我从自动建议下拉列表中选择一个值:

from selenium import webdriver
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By
web1 = webdriver.Chrome(ChromeDriverManager().install())
web1.get('https://reassurez-moi.fr/simulation-tarifaire-assurance-habitation?homeType=1')
#time.sleep(2)
topics_xpath = '//*[@id="home-comparator-base"]/div[2]/div/div[2]/div/form/div[1]/div[1]/div/div[1]/div[2]/div/div[2]/button'
WebDriverWait(web1,2).until(expected_conditions.visibility_of_element_located((By.XPATH, topics_xpath)))
Rue_Adresse = "Rue de la Paix"
last = web1.find_element_by_xpath('//*[@id="home-comparator-base"]/div[2]/div/div[2]/div/form/div[3]/div[1]/div[2]/div/input')
last.send_keys(Rue_Adresse)

尝试这个元素

/html/body/div[5]/div[1]
/html/body/div[5]/div[2]
/html/body/div[5]/div[3]

下拉响应

最新更新