How to reach a dropdown element through partial text in Selenium - python

Asked

Viewed 46 times

0

How can I select an element from a dropdown through part of its name? I want to select an option based on values taken from a database, but these values do not have the full name of the elements of the dropdown element, there is some way to make Selenium search the element through the partial text?

    modelo = googleSheet.modelo.upper().strip()
    select = Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/div/div[1]/form/fieldset[6]/div/ul/fieldset[3]/div/ul/fieldset[3]/div/ul/fieldset/div/ul/li/label'))))
    select.select_by_visible_text(modelo)

In the dropdown option I want to select "Terrano II 2.7 ol foo", but the value of my database is only Terrano II 2.7

Thanks for the help

1 answer

1


For more complex filters than those provided natively, I suggest doing it manually, something like this:

for option in select.options:
    if 'Terrano II 2.7' in option.text:
        select.select_by_visible_text(option.text)
        break

Browser other questions tagged

You are not signed in. Login or sign up in order to post.