hitchtest / hitchselenium

Plugin to run Selenium with firefox using the Hitch testing framework.
GNU Affero General Public License v3.0
1 stars 2 forks source link

'string indices must be integer' TypeError on click #2

Open fcurella opened 8 years ago

fcurella commented 8 years ago

Hi,

I"m try running hitch for the first time, and I'm encountering a 'string indices must be integer' error when clicking on a link.

I've verified the link existing and I can click it from IPython:

In [1]: self.click('sign-up-link')

In [2]:

I'm using the code straight from this template https://github.com/pydanny/cookiecutter-django/tree/master/%7B%7Bcookiecutter.repo_name%7D%7D/tests and running OS X Yosemite + FFox 43.0.4

Python 3.5.0 (default, Sep 23 2015, 04:42:00)
Type "copyright", "credits" or "license" for more information.

IPython 4.0.2 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

Exception occurred in "Sign up and log in":
    /Users/flavio/working_copies/joy/tests/register-and-log-in.test

    2: - Click: djHideToolBarButton
--> 3: - Click: sign-up-link
    4: - Fill form:
          id_email: testuser@domain.com
          id_password1: password
          id_password2: password
          id_username: testuser

[0]: function 'click'   ( self.stacktrace[0].ipython() )
  /Users/flavio/working_copies/joy/tests/.hitch/virtualenv/lib/python3.5/site-packages/hitchselenium/step_library.py

    90 :         item = HitchSeleniumItem(item)
    91 :         if item.is_id:
--> 92 :             self.driver.find_element_by_id(item.html_id).click()
    93 :         else:
    94 :             self.driver.find_elements_by_css_selector(

[1]: function 'click'   ( self.stacktrace[1].ipython() )
  /Users/flavio/working_copies/joy/tests/.hitch/virtualenv/lib/python3.5/site-packages/selenium/webdriver/remote/webelement.py

    73 :     def click(self):
    74 :         """Clicks the element."""
--> 75 :         self._execute(Command.CLICK_ELEMENT)
    76 :
    77 :     def submit(self):

[2]: function '_execute'   ( self.stacktrace[2].ipython() )
  /Users/flavio/working_copies/joy/tests/.hitch/virtualenv/lib/python3.5/site-packages/selenium/webdriver/remote/webelement.py

    452 :             params = {}
    453 :         params['id'] = self._id
--> 454 :         return self._parent.execute(command, params)
    455 :
    456 :     def find_element(self, by=By.ID, value=None):

[3]: function 'execute'   ( self.stacktrace[3].ipython() )
  /Users/flavio/working_copies/joy/tests/.hitch/virtualenv/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py

    199 :         response = self.command_executor.execute(driver_command, params)
    200 :         if response:
--> 201 :             self.error_handler.check_response(response)
    202 :             response['value'] = self._unwrap_value(
    203 :                 response.get('value', None))

[4]: function 'check_response'   ( self.stacktrace[4].ipython() )
  /Users/flavio/working_copies/joy/tests/.hitch/virtualenv/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py

    105 :                   if status is None:
    106 :                       status = value["status"]
--> 107 :                       message = value["value"]["message"]
    108 :                   else:
    109 :                       message = value.get('message', None)

builtins.TypeError

string indices must be integer
crdoconnor commented 8 years ago

Oh wow. Good catch.

This is about selenium not being able to find the log in link because it's hidden behind the django toolbar. Apparently after the toolbar 'hide' was clicked, it didn't wait long enough for it to disappear before it tried to click on the log in link. I think perhaps your computer was running slowly at that point.

This step: Click: djHideToolBarButton shouldn't actually be there. To mitigate this problem and remove the need for having "click: djHideToolBarButton" in every test, you can put the following lines of code at the end of the load_website(self) method:

self.click("djHideToolBarButton")
self.wait_to_appear("sign-up-link")

This reminds me I should submit a pull request to cookiecutter-django to fix this problem.

crdoconnor commented 8 years ago

The "TypeError: string indices must be integer" appears to be a bug in selenium. It ought to give a more meaningful message than that.