Selecting an <option> with selenium in Python

  • 2 Replies
  • 1112 Views
Selecting an <option> with selenium in Python
« 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> ?

*

Ruhit

  • *
  • 22
Re: Selecting an <option> with selenium in Python
« Reply #1 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]

Re: Selecting an <option> with selenium in Python
« Reply #2 on: May 05, 2016, 21:32:46 pm »
Thanks Ruhit!

 

Sitemap 1 2 3 4 5 6 7 8