Selenium: TypeError - undefined is not a constructor (evaluating '_getTagName(currWindow).toLowerCase()')

Created on 6 Jun 2016  路  14Comments  路  Source: SeleniumHQ/selenium

Meta -

OSX 10.11.5
Also on heroku cedar-14 via a Flask app
Selenium Version:
2.53.2
Browser:
PhantomJS
Browser Version:
2

Expected Behavior -

send_keys works well and sends keys to an input/textarea/what have you

Actual Behavior -

selenium.common.exceptions.WebDriverException: Message: TypeError - undefined is not a constructor (evaluating '_getTagName(currWindow).toLowerCase()')

Steps to reproduce -

Background: OS X El capitan locally, heroku on the web. Python 3.4 in venv. Error throws for both. I'm using the Selenium webdriver (2.53.2) Here's the traceback:

*_The desired behavior is for it to send the keys to the value of the web element. *_

The specific problem or error:

WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.CSS_SELECTOR, "#onyen"))
    ).send_keys(onyen)

*_The traceback is *_

Traceback (most recent call last):
  File "driver.py", line 332, in <module>
    to_shopping_cart(phantom=True)
  File "driver.py", line 47, in to_shopping_cart
    ).send_keys(onyen)
  File "/app/.heroku/python/lib/python3.4/site-packages/selenium/webdriver/remote/webelement.py",        line 322, in send_keys
    self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': keys_to_typing(value)})
  File "/app/.heroku/python/lib/python3.4/site-packages/selenium/webdriver/remote/webelement.py", line 457, in _execute
    return self._parent.execute(command, params)
  File "/app/.heroku/python/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line    233, in execute
    self.error_handler.check_response(response)
  File "/app/.heroku/python/lib/python3.4/site-packages/selenium/webdriver/remote/errorhandler.py",     line 165, in check_response
    raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: TypeError - undefined is not a function       (evaluating '_getTagName(currWindow).toLowerCase()')

I have no idea how to fix this traceback, after opening all the files listed.

Here is the shortest code necessary to reproduce the question itself, provided you're in a venv of python 3.4 with selenium 2.53.2

from selenium import webdriver
driver = webdriver.PhantomJS() # webdriver.Firefox() works no problem
driver.get("https://sso.unc.edu/idp/Authn/UserPassword")
WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.CSS_SELECTOR, "#onyen"))
    ).send_keys(onyen)

It is important to note that the same error is thrown on heroku bash and my own machine, however on my own machine the file paths start with /venv/python3.4 instead of /.heroku/python/lib/python3.4.

Most helpful comment

http://stackoverflow.com/questions/37647994/heroku-flask-selenium-cant-find-file-in-traceback-weird-valueerror?noredirect=1#comment62778464_37647994 provides the traceback, the webdriver script and all other necessary information to reproduce the problem or issue.

Thanks so much for taking a look at this!

All 14 comments

Please provide a completely reproducible test case for us that would include a link to a page or html (including css / javascript) along with a WebDriver script to reproduce the issue. Without this there is little to nothing one can do to help with your issue. Please do not expect others volunteering their time to work at reproducing your issue.

When a reproducible test case is provided we can reopen the issue.

http://stackoverflow.com/questions/37647994/heroku-flask-selenium-cant-find-file-in-traceback-weird-valueerror?noredirect=1#comment62778464_37647994 provides the traceback, the webdriver script and all other necessary information to reproduce the problem or issue.

Thanks so much for taking a look at this!

I'm getting this error when using the Splinter wrapper in Python.
I'm trying to interact with a form field inside an iframe, but when I attempt to use the type method on the iframe, I get the exact error above.

@lukeis, should this be re-opened with @Ddfulton's provided repro information?

@michaeltlombardi the provided repro information no longer works as the url given returns a 404. If you can come up with a new case then please provide it. I suspect this is a phantomjs issue, however

@michaeltlombardi actually reading down further of the issue @adamlwgriffiths linked, it does appear to be a phantomjs issue https://github.com/ariya/phantomjs/issues/14211#issuecomment-279742472

the provided repro information no longer works as the url given returns a 404

also, the repro code uses the variable onyen which is not defined anywhere... so it's impossible to tell what the OP might actually be passing to send_keys(). The snippet is also missing 3 imports needed to make it runnable.

FWIW, I can't get this issue to reproduce at all. send_keys works fine with PhantomJS 1.9.8 for fields on every site I have tried.

I've experienced this issue when filling out the Stripe credit card information on Shopify.

To avoid bots cough stripe create an iframe per CC form field. Each iframe only has 1 valid field and the rest are dummies, entering information in any other field marks the data as invalid - conveniently they were previously marked "dummy" and the updated version puts the valid form field name in the iframe name...... -_-. But I digress.

When I was attempting to fill the input fields in, inside these iframes, I was getting the exception.
I can potentially set up a demo shop for you to test this out with.
I don't really have time to debug this any further though.

Ok, I took the time and made a test site and a test script that uses the functions as best I can remember.
I am _not_ seeing the issue though (I think I'm using the same functions).
I believe I've updated PhantomJS since then, so perhaps it was fixed upstream.

@adamlwgriffiths Which version of PhantomJS are you using now?

I'll set up a repro on my end since I ran across this issue over the course of the week.

Using manually installed PhantomJS

$ which phantomjs
/usr/local/bin/phantomjs
$ phantomjs --version
2.1.1
$ python --version
Python 2.7.10 :: Continuum Analytics, Inc.
$ pip search splinter
splinter (0.7.5)                 - browser abstraction for web acceptance
                                   testing
  INSTALLED: 0.7.5 (latest)
$ pip search selenium
selenium (3.0.2)                                  - Python bindings for
                                                    Selenium
  INSTALLED: 2.53.6
  LATEST:    3.0.2

"I've experienced this issue when filling out the Stripe credit card information on Shopify."

I am facing the same issue while filling stripe payment information from coverhound.com. I get the similar error when I execute the below code -
driver.switch_to.frame(driver.find_element_by_name('__privateStripeFrame4')) driver.find_element_by_name('cardnumber').send_keys(5555)

I am using Python 3.5, Phantom Js - 2.1.1, Selenium 3.3.3.

Can you please let me know, what needs to be done to resolve the issue?

I'm not sure if this will help, but here goes...
I use splinter, a wrapper around selenium.
If you can switch to splinter, try the following (or your stripe equivalent) and see if it works for you

# where iframe_expiry is a frame Id I've previously calculated
with browser.get_iframe(iframe_expiry) as iframe:
    element = iframe.find_by_css('form #expiry')
    for key in element.type('10 / 20', slowly=True):
        # it seems type is a generator or similar, without looping over it it wont be done
        assert element.value
Was this page helpful?
0 / 5 - 0 ratings