0

With Python, I want to select each option of a select tag since this HTML code :

<SELECT onchange="top.selectionMediator.campaignSPListBoxChanged();window.campaignSPPeopleFilterBox_listbox.onSelect('LIST_ITEM_ACTION',this);; ; newdd_ipadOnChange(this, event);" onclick="newdd_onListClick(this, event)" id=campaignSPPeopleFilterBox_listbox class=bpDropDownList onkeydown="newdd_onListKeyDown(this, event)" style="WIDTH: 175px; VISIBILITY: hidden" size=4 name=campaignSPPeopleFilterBox_listbox maxWidth="175" index="0">
    <OPTION value=-1 wasSelected="false" wasSelectedTmp="false">-Aucune campagne-</OPTION>
    <OPTION value=163 wasSelected="false" wasSelectedTmp="false">campagne1</OPTION>
    <OPTION value=95 wasSelected="false" wasSelectedTmp="false">campagne2</OPTION>
    <OPTION selected value=113 wasSelected="false" wasSelectedTmp="true">campagne3</OPTION>
</SELECT>

I wrote the following code :

from selenium import webdriver
from selenium.webdriver.ie.options import Options
from selenium.webdriver.support.select import Select

ieOptions = Options()
ieOptions.ignore_protected_mode_settings = True
browser = webdriver.Ie(options=ieOptions)

select = Select(browser.find_element_by_id("campaignSPPeopleFilterBox_listbox"))
for i in range(1,len(select.options)):
    browser.find_element_by_id("campaignSPPeopleFilterBox_listbox_0Button").click()
    # select.options[i].click()
    optionText = select.options[i].text
    browser.find_element_by_xpath("//select[@name='campaignSPPeopleFilterBox_listbox']/option[text()='" + optionText + "']").click()
    # Do something

I manage to select the first item, but when the FOR loop goes to the second, I get the following error message :

selenium.common.exceptions.StaleElementReferenceException: Message: Specified parent element is no longer attached to the DOM

Could you please help me solve this problem?

Thank you in advance for your help!

user78910
  • 349
  • 2
  • 12
Christophe C.
  • 147
  • 3
  • 13

0 Answers0