Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: string indices must be integers in selenium-py 2.49.1 #1497

Closed
nikolas opened this issue Jan 18, 2016 · 14 comments · Fixed by 2gis/contesto#97
Closed

TypeError: string indices must be integers in selenium-py 2.49.1 #1497

nikolas opened this issue Jan 18, 2016 · 14 comments · Fixed by 2gis/contesto#97

Comments

@nikolas
Copy link
Contributor

nikolas commented Jan 18, 2016

When upgrading from selenium 2.48.0 to selenium 2.49.1, I'm getting this error:

Traceback (most recent call last):
        File "/home/travis/build/ccnmtl/worth2/ve/lib/python2.7/site-packages/behave/model.py", line 1456, in run
          match.run(runner.context)
        File "/home/travis/build/ccnmtl/worth2/ve/lib/python2.7/site-packages/behave/model.py", line 1903, in run
          self.func(context, *args, **kwargs)
        File "features/steps/common.py", line 67, in i_click_the_link
          element.click()
        File "/home/travis/build/ccnmtl/worth2/ve/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 75, in click
          self._execute(Command.CLICK_ELEMENT)
        File "/home/travis/build/ccnmtl/worth2/ve/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 454, in _execute
          return self._parent.execute(command, params)
        File "/home/travis/build/ccnmtl/worth2/ve/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 201, in execute
          self.error_handler.check_response(response)
        File "/home/travis/build/ccnmtl/worth2/ve/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 107, in check_response
          message = value["value"]["message"]
      TypeError: string indices must be integers

Here's the failing travis build:
https://travis-ci.org/ccnmtl/worth2/builds/103229032#L1113

And here's an example of the same exception being raised in another Django application:
https://travis-ci.org/ccnmtl/uelc/builds/103229165#L1938

@xavfernandez
Copy link

Same thing with selenium==2.49.2:

Traceback (most recent call last):
  File "/home/xfernandez/dev/project/project/browser_tests.py", line 235, in test_check_tasks
    self.driver.find_element_by_xpath("//button/span[contains(., 'Send')]").click()
  File "/home/xfernandez/.virtualenvs/project/local/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 75, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/home/xfernandez/.virtualenvs/project/local/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 454, in _execute
    return self._parent.execute(command, params)
  File "/home/xfernandez/.virtualenvs/project/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 201, in execute
    self.error_handler.check_response(response)
  File "/home/xfernandez/.virtualenvs/project/local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 107, in check_response
    message = value["value"]["message"]
TypeError: string indices must be integers

@AutomatedTester
Copy link
Member

Please can you create a reduced test case so I don't need to get your whole repo out and see how you build things.

@nikolas
Copy link
Contributor Author

nikolas commented Jan 19, 2016

I'm not familiar enough with Selenium's internals to create a useful test case. However, it seems that the problem is, at the code here: https://github.com/SeleniumHQ/selenium/blob/master/py/selenium/webdriver/remote/errorhandler.py#L107 selenium expects value to be JSON, not a string. We just need to handle the case where it's a string, not a JSON object. In order to do that, my inclination would be to refactor that code a bit since it's already pretty complex. I might come up with a PR for this if no one else does.

@AutomatedTester
Copy link
Member

AutomatedTester commented Jan 19, 2016 via email

@nikolas
Copy link
Contributor Author

nikolas commented Jan 19, 2016

Alright, I'll see if I can narrow down where the problem is to make a test case.

@hmcelroy
Copy link

I'm also getting this error "TypeError: string indices must be integers" on 24 tests after updating selenium after updating firefox (43.0.4). Attached is my test results - you can see in all instances of the type error, there is a click that is setting it off.
test failures gpss-238 en.txt

@barancev barancev added the C-py label Jan 21, 2016
@francoisfreitag
Copy link

I've ran into the same problem, here is a stripped down version of the problem:

<html>
<body>
    <h1>Issue 1497</h1>
    <button id="button1">
        <span id="span1">Click to reproduce</span>
    </button>
</body>
</html>
def test_issue_1497(self):
     self.driver.get('file:///path/to/dev/test.html')
     self.driver.find_element_by_css_selector('#span1').click()

Selenium 2.49.2:

Traceback (most recent call last):
  File "/path/to/test.py", line 6, in test_issue_1497
        self.driver.find_element_by_css_selector('#span1').click()
  File "selenium/webdriver/remote/webelement.py", line 75, in click
    self._execute(Command.CLICK_ELEMENT)
  File "selenium/webdriver/remote/webelement.py", line 454, in _execute
    return self._parent.execute(command, params)
  File "selenium/webdriver/remote/webdriver.py", line 201, in execute
    self.error_handler.check_response(response)
  File "selenium/webdriver/remote/errorhandler.py", line 107, in check_response
    message = value["value"]["message"]
TypeError: string indices must be integers

The workaround for me was to select the button element, not the span that's inside.

edit2: stacktrace 2.49.2

@sumenon
Copy link

sumenon commented Jan 28, 2016

I am facing this very same issue.Waiting for a fix.

nikolas added a commit to nikolas/selenium that referenced this issue Jan 28, 2016
This should address the error documented here: SeleniumHQ#1497

Yes, it's ugly code.. alternatives welcome.
@nikolas
Copy link
Contributor Author

nikolas commented Jan 28, 2016

@sumenon Here is a workaround: #1547

Let me know if it works.

AutomatedTester pushed a commit that referenced this issue Jan 28, 2016
This should address the error documented here: #1497

Signed-off-by: AutomatedTester <david.burns@theautomatedtester.co.uk>
@ernestm
Copy link

ernestm commented Jan 28, 2016

I'm having this issue too, glad to see there's a fix in flight...

openstack-gerrit pushed a commit to openstack/openstack that referenced this issue Jan 29, 2016
Project: openstack/requirements  950b5031ee73e7145ca795659ef68917ae74787a

Cap Selenium package to not exceed version 2.49

Current versions of selenium package greater or equal than 2.49
contain a bug SeleniumHQ/selenium#1497 that
prevents Horizon integration tests from passing. Once the fixed
Selenium is released, we'll just exclude problematic versions and
remove the cap.

Change-Id: I9a426757b19159d9ed5ad508bf7f549015c1cdd7
Closes-Bug: #1539197
openstack-gerrit pushed a commit to openstack/requirements that referenced this issue Jan 29, 2016
Current versions of selenium package greater or equal than 2.49
contain a bug SeleniumHQ/selenium#1497 that
prevents Horizon integration tests from passing. Once the fixed
Selenium is released, we'll just exclude problematic versions and
remove the cap.

Change-Id: I9a426757b19159d9ed5ad508bf7f549015c1cdd7
Closes-Bug: #1539197
openstack-gerrit pushed a commit to openstack/openstack that referenced this issue Jan 29, 2016
Project: openstack/requirements  950b5031ee73e7145ca795659ef68917ae74787a

Cap Selenium package to not exceed version 2.49

Current versions of selenium package greater or equal than 2.49
contain a bug SeleniumHQ/selenium#1497 that
prevents Horizon integration tests from passing. Once the fixed
Selenium is released, we'll just exclude problematic versions and
remove the cap.

Change-Id: I9a426757b19159d9ed5ad508bf7f549015c1cdd7
Closes-Bug: #1539197
@barancev
Copy link
Member

barancev commented Feb 1, 2016

Please retest in 2.50

@francoisfreitag
Copy link

2.50.0 does not fix the issue.

pip freeze | grep selenium                                                            
selenium==2.50.0
ERROR: test_issue_1497
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/path/to/tests.py", line 178, in test_issue_1497
    self.driver.find_element_by_css_selector('#span1').click()
  File "selenium/webdriver/remote/webelement.py", line 75, in click
    self._execute(Command.CLICK_ELEMENT)
  File "selenium/webdriver/remote/webelement.py", line 460, in _execute
    return self._parent.execute(command, params)
  File "selenium/webdriver/remote/webdriver.py", line 201, in execute
    self.error_handler.check_response(response)
  File "selenium/webdriver/remote/errorhandler.py", line 107, in check_response
    message = value["value"]["message"]
TypeError: string indices must be integers

@kurkha
Copy link

kurkha commented Feb 1, 2016

I'm also still having this issue in 2.50 with Firefox (at least). I have the following structure:

<div class="ui-dialog-buttonset">
    <button aria-disabled="false" role="button" class="ui-button ui-widget ui-state-default ui-corner-all  
    ui-button-text-only" type="button">
        <span class="ui-button-text">Ok</span>
    </button>

Now, I get the error by using the following command. It's Robot code, but the traceback is identical for the Selenium-related part - except, of course, for the "find_element_by_css_selector":

Click Element xpath=//button/span[@class='ui-button-text' and contains(., 'Ok')]

Again, 2.48 works fine.

@barancev
Copy link
Member

barancev commented Feb 1, 2016

Fixed by commit c68ace0

@barancev barancev closed this as completed Feb 1, 2016
evgeny-kapov pushed a commit to evgeny-kapov/powtenium that referenced this issue Jun 18, 2019
This should address the error documented here: SeleniumHQ/selenium#1497

Signed-off-by: AutomatedTester <david.burns@theautomatedtester.co.uk>
@lock lock bot locked and limited conversation to collaborators Aug 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants