Selenium giving grief: NoneType object is not subscriptable

1,560 views
Skip to first unread message

Phantom AP1

unread,
Mar 19, 2017, 10:32:45 AM3/19/17
to obey-the-test...@googlegroups.com
Hello fellow Goat acolytes,

All of a sudden a problem has crept into my functional test for the layout and styling and I can't figure it out. I decided to post in the forum instead of fouling up Harry's comment section of his books website even further with my incessant questions.

As far as I can tell it can't complete the math to assert the relative location of the main list inputbox, which in turn is due to Selenium's internals not getting a numerical value for ['x'].
At first I thought it was because I had moved to Python 3.6 and Django 1.11b1 but I made a new virtualenv with Python 3.5.2 and Django 1.10, the setup with which I knew it was working previously.
If I spin up the Django server manually and have a look with Firefox the page looks fine and all the other FTs work (except for the one I'm working on obviously), so I'm at a loss as to what happened.

The error I get is:
======================================================================
ERROR
: test_layout_and_styling (functional_tests.test_layout_and_styling.LayoutAndStylingTest)
----------------------------------------------------------------------
Traceback (most recent call last):
 
File "/home/iman/Env/selenium-test/35-test/functional_tests/test_layout_and_styling.py", line 15, in test_layout_and_styling
    inputbox
.location['x'] + inputbox.size['width'] / 2,
 
File "/home/iman/Env/selenium-test/lib/python3.5/site-packages/selenium/webdriver/remote/webelement.py", line 403, in location
    new_loc
= {"x": round(old_loc['x']),
TypeError: 'NoneType' object is not subscriptable

----------------------------------------------------------------------

I tried to do some Python CLI voodoo and I found out that it's specifically the call to inputbox.location that seems to be the problem. I would expect that call to give me a dict with x and y values, right?
Also, yes I know this is slightly different than the book example, but I think it comes down to the same. The get_item_input_box() didn't work in the CLI, said it's not an attribute of the WebDriver object.

>>> inputbox = browser.get_item_input_box()
Traceback (most recent call last):
 
File "<stdin>", line 1, in <module>
AttributeError: 'WebDriver' object has no attribute 'get_item_input_box'
>>> inputbox = browser.find_element_by_id('id_text')
>>> inputbox.location
Traceback (most recent call last):
 
File "<stdin>", line 1, in <module>
 
File "/home/iman/Env/selenium-test/lib/python3.5/site-packages/selenium/webdriver/remote/webelement.py", line 403, in location
    new_loc
= {"x": round(old_loc['x']),
TypeError: 'NoneType' object is not subscriptable
>>> inputbox.id
'da24cd29-d4cb-4777-abd1-8a76c950df33'
>>> inputbox._w3c
True

The last two calls were to be sure that I did actually have a WebDriver object :)

But that's as far as I can get, I don't understand what is happening here. I guess it's a Selenium specific problem? I'll happily continue and just skip over the (arguably silly) layout FT, but would like to eventually get it to work again, because I fear the wrath of the Goat otherwise :(

Kind regards,
Iman van Assum

Harry Percival

unread,
Mar 19, 2017, 11:51:32 AM3/19/17
to Phantom AP1, obey-the-test...@googlegroups.com

I saw this problem a coupke of days ago. You need to upgrade geckodriver and selenium i think.


--
You received this message because you are subscribed to the Google Groups "Obey the testing goat! Test-Driven Web Development with Python book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-go...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

--
Harry Percival
+44 78877 02511

Richard Bailey

unread,
Mar 19, 2017, 2:22:02 PM3/19/17
to Harry Percival, Phantom AP1, obey-the-test...@googlegroups.com

Yes, I saw this Friday. I can confirm updating gecko driver worked. I had already updated Firefox and selenium. One of those broke things.

Phantom AP1

unread,
Mar 19, 2017, 5:32:40 PM3/19/17
to Obey the testing goat! Test-Driven Web Development with Python book, harry.p...@gmail.com, phant...@gmail.com
Yeah I am already running latest Selenium so nothing to change there.
I am 1 version behind on geckodriver though, 0.14.0 instead of 0.15.0, will update it and let you know how things are then.

Thanks for the tip!

Op zondag 19 maart 2017 19:22:02 UTC+1 schreef Richard Bailey:
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-goat-book+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--

--
Harry Percival
+44 78877 02511

--
You received this message because you are subscribed to the Google Groups "Obey the testing goat! Test-Driven Web Development with Python book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-goat-book+unsub...@googlegroups.com.

Phantom AP1

unread,
Mar 19, 2017, 5:43:29 PM3/19/17
to Obey the testing goat! Test-Driven Web Development with Python book
Alright, after downloading latest geckodriver I can confirm the following combination works:

Python 3.6.0
Django 1.11b1
Selenium 3.3.1
Geckodriver 0.15.0

Thanks for the help fellas :)

Devendra Saroj

unread,
Jul 9, 2019, 4:26:19 AM7/9/19
to Obey the testing goat! Test-Driven Web Development with Python book
Well the above error is because of this piece of code 
inputbox = browser.find_element_by_id('id_text')
You are telling the web driver to find only one element by the id
id_text
hense it isn't subscriptable.

Change it to inputbox = browser.find_elements_by_id('id_text')
and it will work fine. You see the difference there, It's
elements

instead of
 element

Reply all
Reply to author
Forward
0 new messages