【发布时间】:2021-07-10 13:46:10
【问题描述】:
我正在尝试通过 python 脚本填写此表单:https://reassurez-moi.fr/simulation-tarifaire-assurance-habitation?homeType=1
但不幸的是,我不知道如何在 Python 中使用 Selenium 处理自动建议下拉菜单。
事实上,我想在写街道名称时选择下拉列表的第一个元素(法语:'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)
【问题讨论】:
标签: python selenium google-chrome web-scraping dropdown