I am working through a book repository, specifically chapter 5 of Test-Driven Development, which can be found at this repository: https://github.com/hjwp/book-example/tree/chapter_05 . When I attempt to run the functional tests, which create a simple POST form, submit some input, and then check to see whether the input has been rendered, I get the following error:
======================================================================
FAIL: test_can_start_a_list_and_retrieve_it_later (__main__.NewVisitorTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "book-example-chapter_05/functional_tests.py", line 45, in test_can_start_a_list_and_retrieve_it_later
self.check_for_row_in_list_table('1: Buy peacock feathers')
File "book-example-chapter_05/functional_tests.py", line 18, in check_for_row_in_list_table
self.assertIn(row_text, [row.text for row in rows])
AssertionError: '1: Buy peacock feathers' not found in ['']
---------------------------------------------------------------------
It seems from a discussion on the mailing list that this might be due to the browser not receiving the 'ENTER' key. When I change the line to inputbox.send_keys('Buy peacock feathers\n')
, to directly send a new line character, I get the following error:
======================================================================
ERROR: test_can_start_a_list_and_retrieve_it_later (__main__.NewVisitorTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "book-example-chapter_05/functional_tests.py", line 44, in test_can_start_a_list_and_retrieve_it_later
inputbox.send_keys(Keys.ENTER)
File "/Users/r/virtualenvs/r/bin/python3venv/lib/python3.4/site-packages/selenium/webdriver/remote/webelement.py", line 322, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': typing})
File "/Users/r/virtualenvs/r/bin/python3venv/lib/python3.4/site-packages/selenium/webdriver/remote/webelement.py", line 448, in _execute
return self._parent.execute(command, params)
File "/Users/r/virtualenvs/r/bin/python3venv/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 196, in execute
self.error_handler.check_response(response)
File "/Users/r/virtualenvs/r/bin/python3venv/lib/python3.4/site-packages/selenium/webdriver/remote/errorhandler.py", line 181, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: Element not found in the cache - perhaps the page has changed since it was looked up
Stacktrace:
at fxdriver.cache.getElementAt (resource://fxdriver/modules/web-element-cache.js:9348)
at Utils.getElementAt (file:///var/folders/k5/t81w4vh94rg1ps_h5tb_vbr00000gn/T/tmp0cz8wkgo/extensions/fxdriver@googlecode.com/components/command-processor.js:8942)
at fxdriver.preconditions.visible (file:///var/folders/k5/t81w4vh94rg1ps_h5tb_vbr00000gn/T/tmp0cz8wkgo/extensions/fxdriver@googlecode.com/components/command-processor.js:9980)
at DelayedCommand.prototype.checkPreconditions_ (file:///var/folders/k5/t81w4vh94rg1ps_h5tb_vbr00000gn/T/tmp0cz8wkgo/extensions/fxdriver@googlecode.com/components/command-processor.js:12626)
at DelayedCommand.prototype.executeInternal_/h (file:///var/folders/k5/t81w4vh94rg1ps_h5tb_vbr00000gn/T/tmp0cz8wkgo/extensions/fxdriver@googlecode.com/components/command-processor.js:12643)
at fxdriver.Timer.prototype.setTimeout/<.notify (file:///var/folders/k5/t81w4vh94rg1ps_h5tb_vbr00000gn/T/tmp0cz8wkgo/extensions/fxdriver@googlecode.com/components/command-processor.js:623)
----------------------------------------------------------------------
Ran 1 test in 5.511s
so that seems to suggest that there is an error with the DOM tree, and the next element it tries to find (one with an id equal to 'id_list_table') cannot be found.
Why is this the case? How can I have Selenium test the addition of a list item and its existence in the table I've created?