Selenium in Python only executing one function

34 Views Asked by At

I am creating automation using Selenium in Python but when I run this code it only executes the first function only correctly which is the select_filter_options('Seniority', selected_seniority) and the other functions next to it are neglected by the script. What do you think the problem of my code? Thank you!!!

def select_filter_options(filter_name, selected_options):
    # Find and click the filter button
    filter_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, f"//div[text()='{filter_name}']/ancestor::a")))
    filter_button.click()

    # Find and click the span element to open the dropdown
    span = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='rs-input-group-addon']")))
    span.click()

    # Loop through each selected option
    for option in selected_options:
        # Find and click the item label for the option
        item_label_xpath = f"//div[@class='SearchFilterFieldInput__ItemLabel-giZgoQ ifCFA' and text()='{option}']"
        item_label = WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, item_label_xpath)))
        item_label.click()

# Select seniority options
select_filter_options('Seniority', selected_seniority)

# Select department options
select_filter_options('Department', selected_departments)

# Select employee size options
select_filter_options('Employee Size', selected_sizes)

# Select revenue options
select_filter_options('Revenue', selected_revenue)

All the functions on filters be executed properly

0

There are 0 best solutions below