
Python Selenium - selectbox - option is stale; either the element is no longer attached to the DOM
Dobrý den,
Když chci proklikat celý selectbox s options v python selenium pomocí této konstrukce:
Tak se brzo objeví chyba:
optionis stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
Nevíte někdo co s tím? Chci prostě proklikat celý selectbox a tím logicky dochází k refresh stránky a v tom bude problém. Jak to prosím v python selenium vyřešit?
Díky
Dobrý den,
chybu v Python Selenium "selenium.common.exceptions.StaleElementReferenceException: Message: The element reference of < option > is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed" jsem vyřešil takto:
1.) načíst všechny option values do array firstLoopArray
2.) pak teprve options z firstLoopArray iterovat v cyklu + přidat lambda driver
-------------------------------------------------------------------------------------------------------------
Další moje obecné poznámky pod čarou
# jak selektovat dle textu
# select by value
Když chci proklikat celý selectbox s options v python selenium pomocí této konstrukce:
secondSelectId = 'frm-competibleList-competitionsStilter-form-coetitionsStage'
secondSelectBoxx = driver.find_element_by_id(secondSelectId)
secondCountOptions = len(secondSelectBoxx.find_elements_by_tag_name('option'))
secondOptions = [x for x in secondSelectBoxx.find_elements_by_tag_name("option")]
print('Total second TS: ', secondCountOptions)
# loop all options
for secondOption in secondOptions:
secondOptionTabValue = secondOption.get_attribute("value")
print(secondOptionTabValue)
select = Select(driver.find_element_by_id(secondSelectId))
# select by visible text
# select.select_by_visible_text('xyz')
# select by value
select.select_by_value(secondOptionTabValue)
time.sleep(1)
Tak se brzo objeví chyba:
optionis stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
Nevíte někdo co s tím? Chci prostě proklikat celý selectbox a tím logicky dochází k refresh stránky a v tom bude problém. Jak to prosím v python selenium vyřešit?
Díky
ODPOVĚĎ
Dobrý den,
chybu v Python Selenium "selenium.common.exceptions.StaleElementReferenceException: Message: The element reference of < option > is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed" jsem vyřešil takto:
1.) načíst všechny option values do array firstLoopArray
firstLoopArray = []
for firstValue in firstOptions:
firstLoopArray.append(firstValue.get_attribute("value"))
print (firstValue.get_attribute("value"))
2.) pak teprve options z firstLoopArray iterovat v cyklu + přidat lambda driver
for firstOption in firstLoopArray:
print('Item firstOption: ', firstOption)
WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath("//option[@value='{0}']" .format(firstOption)))
print("Xpath: //option[@value='{0}']" .format(firstOption))
-------------------------------------------------------------------------------------------------------------
Další moje obecné poznámky pod čarou
# jak selektovat dle textu
select.select_by_visible_text('xyz')
# select by value
select.select_by_value(firstOption)
Show english version