How can I click a dropdown menu and select a gender with Python

I am trying to create a Python program which can fill the form on this website:
https://www.gewobag.de/fuer-mieter-und-mietinteressenten/mietangebote/0100-02559-0401-0074/

My first goal was to select “Anfrage senden” which means send a request and then the form appears. After that I wanted to select “Anrede” which means Salutation but it doesn’t work.

I have written the following code:

`from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
import time

# Replace with the path to your webdriver executable
geckodriver_path = '/usr/local/bin/geckodriver'

# Initialize the WebDriver for Firefox
driver = webdriver.Firefox(executable_path=geckodriver_path)

driver.maximize_window()  # For maximizing window
driver.implicitly_wait(20)  # Gives an implicit wait for 20 seconds

# Navigate to the form page
driver.get('https://www.gewobag.de/fuer-mieter-und-mietinteressenten/mietangebote/0100-02559-0401-0074/')

# Wait for the "Alle Cookies akzeptieren" button to be clickable and click it
cookies_accept_button = WebDriverWait(driver, 20).until(
    EC.element_to_be_clickable((By.CSS_SELECTOR, 'a._brlbs-btn-accept-all'))
)
cookies_accept_button.click()

# Wait for the "Anfrage Senden" button to be clickable and click it
try:
    anfrage_button = WebDriverWait(driver, 20).until(
        EC.presence_of_element_located((By.XPATH, '//button[contains(text(), "Anfrage senden")]'))
    )
    driver.execute_script("arguments[0].scrollIntoView(true);", anfrage_button)  # Scroll to the button
    time.sleep(1)  # Give time for any scrolling animation to complete
    driver.execute_script("arguments[0].click();", anfrage_button)  # Click using JavaScript
except Exception as e:
    print("An error occurred while clicking the 'Anfrage Senden' button:", e)

# Use JavaScript to click the Anrede dropdown and select 'Herr'
try:
    anrede_dropdown = WebDriverWait(driver, 30).until(
        EC.element_to_be_clickable((By.XPATH, "//div[@formcontrolname='salutation']//div[contains(@class, 'ant-select-selection__placeholder')]"))
    )
    driver.execute_script("arguments[0].click();", anrede_dropdown)
    print("Anrede dropdown clicked")

    herr_option = WebDriverWait(driver, 30).until(
        EC.visibility_of_element_located((By.XPATH, "//ul[contains(@class, 'ant-select-dropdown-menu')]//li[@role='option' and contains(text(), 'Herr')]"))
    )
    driver.execute_script("arguments[0].scrollIntoView(true);", herr_option)  # Scroll to the option
    time.sleep(1)  # Give time for any scrolling animation to complete
    driver.execute_script("arguments[0].click();", herr_option)
    print("Herr option selected")
except Exception as e:
    print("An error occurred while selecting 'Herr':", e)



# List of user details to be filled in the form
user_details = [
    {
        "email": "[email protected]",
        "first_name": "samplename",
        "surname": "samplesurname",
        "street": "samplestreet",
        "house_number": "39",
        "postal_code": "23455",
        "city": "Samplecity"
    },
    {
        "email": "email2@exom",
        "first_name": "Jane",
        "surname": "Smith",
        "street": "456 Elm St",
        "house_number": "2B",
        "postal_code": "67890",
        "city": "Munich"
    },
   
]

wait = WebDriverWait(driver, 30)

driver.quit()


New contributor

MrOmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật