Home > Blockchain >  Cant Use Select In Selenium, Gives 'Select' is not defined Error
Cant Use Select In Selenium, Gives 'Select' is not defined Error

Time:10-09

I'm trying use select in selenium, but keep getting Select is not defined.,

Does select need to be installed as a pip or something?

I'm trying to select a drop down item

mySelect = Select(driver.find_element_by_id("op-order-type"))
mySelect.select_by_index(0)

CodePudding user response:

Load it as the following -

from selenium.webdriver.support.ui import Select

mySelect = Select(driver.find_element_by_id("op-order-type"))
mySelect.select_by_index(0)

CodePudding user response:

Select is not defined 

is probably cause you are missing the below import

from selenium.webdriver.support.select import Select

importing the above should get the job done.

Also, make sure indexing is not recommended in automation :

By preference, you should use :

mySelect = Select(driver.find_element_by_id("op-order-type"))
mySelect.select_by_value('option value here')

then

mySelect.select_by_visible_text('')

and then if nothing works, finally resort should be index.

  • Related