I am getting this error on selenium 'NoneType' object has no attribute 'options'

select = driver.find_element_by_xpath('//select[@id="select_noti_segments_in"]').click()
for index in range(len(select.options)):
        select = driver.find_element_by_xpath('//select[@id="select_noti_segments_in"]')
        select.select_by_index(1)
        time.sleep(5)

for index in range(len(select.options)): AttributeError: 'NoneType' object has no attribute 'options' I am getting this error when i run the python script may i know why i am getting this and how can i resolve this

1 answer

  • answered 2018-11-08 07:35 Andersson

    Simply remove call of click from select definition:

    select = driver.find_element_by_xpath('//select[@id="select_noti_segments_in"]')
    

    Also you need to import Select class and use it as below:

    from selenium.webdriver.support.ui import Select
    
    select = Select(driver.find_element_by_id('select_noti_segments_in'))
    select.select_by_index(1)