문제

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