Frage

I'm trying to implement a data driven test approach using Selenium (Python) but I've run into an issue selecting dynamic values from multiple combo boxes. I'm currently aware of one option, using method driver.execute_script("JAVASCRIPT TO GET COMBO BOX OPTION") but hard coding the values defeats the purpose of automated data driven testing. Is there any other solution?

P.S Please let me know if there is any additional info needed.

Thanks, Eric

War es hilfreich?

Lösung

Don't do that.. that's bad.. don't delegate this to JS when Selenium can handle it just fine.

You can try something like -

el = driver.find_element_by_id('id_of_select')
for option in el.find_elements_by_tag_name('option'):
    if option.text == 'The Option I Am Looking For':
        option.click()

I can't find any documentation for it in Python, but there is a class named SElect which has a couple methods that you can use, like, select_option_by_visible_text

Andere Tipps

I think this should $("#id").val() give you the value i guess

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top