TestProject Forum

General => Selenium => Topic started by: Robert on May 03, 2016, 19:27:06 pm

Title: Selecting an <option> with selenium in Python
Post by: Robert on May 03, 2016, 19:27:06 pm
I need to select a <option> child of a <select>.

I have a reference to the option WebElement I wish to select.
I used click() / select() but they are not working.

What's the proper method to select <option> ?
Title: Re: Selecting an <option> with selenium in Python
Post by: Ruhit on May 04, 2016, 15:42:13 pm
Try:

Code
ele = driver.find_element_by_id('selectEle')
for option in ele.find_elements_by_tag_name('option'):
    if option.text == 'your text':
        option.click()
        break
[code]
Title: Re: Selecting an <option> with selenium in Python
Post by: Robert on May 05, 2016, 21:32:46 pm
Thanks Ruhit!