Question

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

Was it helpful?

Solution

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top