Temporary workaround to StaleElementReferenceException in PAN3

This commit is contained in:
axl89 2016-05-27 02:39:08 +02:00
parent cd4a9ad60f
commit 066d4ffd8a
1 changed files with 18 additions and 6 deletions

View File

@ -5,6 +5,7 @@ from selenium import webdriver
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import StaleElementReferenceException
class PAN3(PandoraWebDriverTestCase): class PAN3(PandoraWebDriverTestCase):
@ -40,12 +41,23 @@ class PAN3(PandoraWebDriverTestCase):
driver.find_element_by_xpath('//*[@id="menu_tab"]//a[contains(@href,"ver_agente")]').click() driver.find_element_by_xpath('//*[@id="menu_tab"]//a[contains(@href,"ver_agente")]').click()
element_text = refresh_N_times_until_find_element(driver,5,"table1-1-7",how=By.ID).text element_text = refresh_N_times_until_find_element(driver,5,"table1-1-7",how=By.ID).text
try: max_retries = 3
self.assertEqual("1", element_text.lstrip().rstrip()) # The lstrip.rstrip is done because if not, this error is raised: "'1' != u'1 '" i = 1
except AssertionError as e: element_text = ""
self.verificationErrors.append(str(e))
while (i <= max_retries): # Temporary workaround to weird StaleElementReferenceException exceptions due Javascript altering the DOM
try:
element_text = refresh_N_times_until_find_element(driver,5,"table1-1-7",how=By.ID).text
self.assertEqual("1", element_text.lstrip().rstrip()) # The lstrip.rstrip is done because if not, this error is raised: "'1' != u'1 '"
except StaleElementReferenceException as e_stale:
i = i+1
if i > max_retries:
self.verificationErrors.append(str(e))
break
else:
next
except AssertionError as e:
self.verificationErrors.append(str(e))
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()