I have been tasked with providing a selenium test (using Python) on a webpage for which I did not write the source code (I don't know much about web development, but from what I was told, it was written using D3 and JQuery). The website generates graphs, and there are a few dropdown menus with options. I'm trying to create every possible graph with these options. To do so, I create a Select object from the dropdown menu WebElement and extract the text of each option in the dropdown. Later on, I use this text to recursively go through each dropdown and enter each valid option to generate the graphs. However, I sometimes (not always, and it seems to be relatively random) encounter a StaleElementReferenceException while trying to extract this list of options, and it is because of the below code (it happens on the options.append(op.get_attribute("text")) line). I have been searching previous questions and documentation on this exception, and I have yet to find an answer than helps me.
#find all of the options
# create list of string options before, so as to avoid StaleElementReferenceException's
# as much as possible
el = driver.find_element(By.ID,node.element)
d = Select(el)
options = []
for op in d.options:
try:
options.append(op.get_attribute("text"))
except StaleElementReferenceException:
print >>sys.stderr, 'StaleElementReferenceException getting text from \'' + node.element + '\' element'
Any input is very helpful! Thank you.
EDIT: Here is an HTML snippet example of one of the dropdowns:
<select class="dropdown" id="datatype" name="datatype" style="display: none;">
<option value="solar_radiation" selected="selected">solar radiation</option>
<option value="windspeed">windspeed</option>
<option value="airtemperature">airtemperature</option>
...
</select>