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

有帮助吗?

解决方案

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

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top