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

Created on 19 Apr 2016  路  37Comments  路  Source: ariya/phantomjs

I create the auto application to testing website in CSharp using Selenium and PhantomJS.

I have a problem when to try SendKeys("values") to the website.

<section id="login">
    <form class="login">
        <input type="text" id="login-username">
    </form>
</section>

It throws exception:

    Message "Unexpected error. TypeError - undefined is not a constructor 
   (evaluating '_getTagName(currWindow).toLowerCase()')" string

My code like:

element.FindElementById("login-username").SendKeys("User1");

I updated PhantomJS to the latest version.

stale

Most helpful comment

@elodszopos: this project/github is not an exclusive boys club!
Please use non-exclusive language.

All 37 comments

I have this problem as well, the given solution is to downgrade PhantomJS to 1.9.8, but I do not think this is a good solution. Does anyone have any input?

I have a similar problem when I use .contain.text() from chai-enzyme. I'm not sure is it the same problem or not, but looks like it is. It works fine in Chrome, but if I run tests in Phantom, I receive the next error message:

undefined is not a constructor (evaluating 'actual.includes(String(arg1))')

It refers to this line in chai-enzyme:
https://github.com/producthunt/chai-enzyme/blob/master/src/assertions/text.js#L7

If it may help, here is the test which produces the error:

expect(wrapper).to.contain.text('alert')

And it works fine in Phantom, when I change it to this:

expect(wrapper.contains('alert')).to.be.ok

Sorry, if this bug is not related to Phantom, but the tests work fine in Chrome and at first glance the problem in Pahtom itself.

I also get this when executing String.prototype.endsWith()

The same issue when I using phantomjs to test my website. Phantom cannot recognize a function written by bootstrap-progressbar.js and give the same error. So I use page.includeJS() to include the bootstrap-progressbar.js before I start my test. It works properly then.

But I wonder why? Should phantomjs include all the JS that I used in my webpage? Why it can recognize jquery, other js plugins but the bootstrap-progressbar.js?

Did I miss something or did something wrong?

Hey boys. I'll have to +1 this.

undefined is not a constructor (evaluating 'filters.find(function (obj) {
...
undefined is not a constructor (evaluating 'brands.includes(brand)')
...

And lots n lots more. It seems array proto methods aren't working as expected. Using

PhantomJS 2.1.1 (Mac OS X 0.0.0)

All my tests pass under karma in 5 different browsers, PhantomJS2 doesn't seem to handle them. I tried to shim the said methods using Karma config to no avail.

This will be fixed in 2.5

@Vitallium yeah, read up about it. Anxiously looking forward to it. Keep up the good work boys n girls! cc @varac :)

Thanks, @Vitallium . I hope to keep up your process.

@elodszopos: this project/github is not an exclusive boys club!
Please use non-exclusive language.

@elodszopos I was able to work around this issue by including the babel-polyfill in my entry file.

Thanks man, @mariotacke - I'll give it a go too.

@Vitallium @elodszopos do you have a link to an explanation of the fix?

i debugged this issue a while back and the root cause was ghostdriver calling javascript eval on a page with a content security policy. it should be fixed on my master branch.

not sure why a polyfill would fix this since phantomjs 2.1.1 has toLowerCase.

@jesg: can you provide a link to the commit? I've looked into your master branch commits and last commit was March 9th, 2016.

I come cross the same issue when I write test file. So I include the babel-polyfill in the test file. Then, it works.

tests/index.js

require('babel-polyfill'); // Top line
// ...

Any solution to this? This happens to us with an input inside iframe too. Went through all the pages on google couldn't find a solution. It seems like nobody knows what's going on even the phantom's own developers

@jyxt does your page have a Content Security Policy? if not can you provide a reproducible example.

@jesg is there a problem with the examples already listed?

@monkpit

is there a problem with the examples already listed?

yes. they do not provide the version of phantomjs, or a detailed example. there is not enough information in this thread to identify the root cause.

see @eos1d3's comments in issue detro/ghostdriver#486 for a good example. eos1d3's analysis was detailed enough that i was able to identify and fix the issue.

I am running into the same issue. I am using Selenium webdriver, NUnit, C# and PhantomJs as ghost browser. I downgraded the PhantomJs version to 1.9.8 and 1.9.6, still the same error. Its throwing "Unexpected error. TypeError - undefined is not a constructor (evaluating '_getTagName(currWindow).toLowerCase()')"} in the step element.SendKeys(text); Any suggestion/workaround, guys?

@Alex1990: do you have a commit or example code showing this? I don't see how requiring babel-polyfill will help without actually using some sort of injection or transformation middleware.

@mariotacke: how are you injecting the polyfill? I'm not using karma or anything just straight phantomjs.

I am experiencing the same problem when using sendKeys() on an element.

org.openqa.selenium.UnsupportedCommandException: TypeError - undefined is not a constructor (evaluating '_getTagName(currWindow).toLowerCase()')

I am using Selenium (Java) and have tried the following versions:

selenium-java 2.53.1, 3.3.1
PhantomJS binary 2.0.0, 2.1.1
PhantomJSDriver 1.2.1, 1.4.0

The page I am trying to test does use SCP disallowing unsafe-eval, so I can't use executeScript() to set the value on the field either

"Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script...

I have also tried all possible combinations of the PhantomJS CLI arguments --web-security=no, --ignore-ssl-errors=yes, ssl-protocl=any, ssl-protocol=tlsv1

Currently trying version 2.5, as @Vitallium says this should be fixed, however I am having other unrelated problems so far. Will update in case I get any further.

Edit: Running on windows

Same here !

Using myArray.includes(myValue).

Fixed it opting in for the (ember-cli-)babel polyfills like that:

// ember-cli-build.js

var app = new EmberApp(defaults, {
  'ember-cli-babel': {
    includePolyfill: true
  }
});

As stated in ember-cli-babel documentation.

PhantomJS: 2.1.1
Mac OS Sierra: 10.12.3
EmberJS: 2.4.6
Ember-cli-babel: 5.2.4

鉂わ笍

Hi Guys,

Did anyone get the solution for this issue?

PhantomJS 2.1.1 (Mac OS X 0.0.0) Test Case encountered a declaration exception FAILED
TypeError: undefined is not a constructor

I am using protractor for testing.

Same here. All are perfectly working with Chrome but with PhantomJs I'm getting weird errors (undefined is not a constructor).

Proposed above change to ember-cli-build.js helped. Is there some fix without changes inember-cli-build.js ?

Add me to the list. I'm trying to work on a page in NetSuite.

Same here

Install babel-polyfill and add it on files list:

files: ['node_modules/babel-polyfill/dist/polyfill.js', 'specs/**/*.ts']

worked for me.

I ran into this issue and installed babel-polyfill but now I have to avoid decorator because Error: Missing required @injectable annotation in: MockRestClient.

And my MockRestClient.ts is:

...
import {decorate, inject, injectable} from "inversify";

export class MockRestClient implements IRestClient {
    constructor(@inject("Factory<XHRInstance>") xhrFactory: (config?: XHRRequestConfig) => XHRInstance) {
        let xhr: XHRInstance = this.service = xhrFactory({});
    }

...
}

decorate(injectable(), MockRestClient);

export default MockRestClient;

Now I ran into TypeError: undefined is not a constructor (evaluating 'Reflect.decorate(decorators, target)')

OK it seems that I have to use import "reflect-metadata"; in each test file that uses reflection.

I tried to add files: ["node_modules/reflect-metadata/Reflect.js",...] to the karma config. But with no lucK

Same issue running Wallaby.js.

Trying to get this working with WebdriverIO. I've tried requiring babel-polyfill in several places with no luck.

I need a patch for this badly. @jesg Any way to do a build with phantomjs 2.1.1 with the latest of ghostdriver? Or is there a way to launch phantomjs 2.1.1 and have it point to the latest ghostdriver binary?

Any way to do a build with phantomjs 2.1.1 with the latest of ghostdriver?

yes, my branch backport-ghostdriver-2-0-to-phantomjs-2-1 backports ghostdriver to phantomjs 2.1.1. you should follow the instructions.

Or is there a way to launch phantomjs 2.1.1 and have it point to the latest ghostdriver binary?

you can use the npm module or the bash script.

Has this been fixed? I'm getting the same error with native js foreach

Due to our very limited maintenance capacity (see #14541 for more details), we need to prioritize our development focus on other tasks. Therefore, this issue will be automatically closed. In the future, if we see the need to attend to this issue again, then it will be reopened. Thank you for your contribution!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sinojelly picture sinojelly  路  3Comments

yairza picture yairza  路  6Comments

qaDream77 picture qaDream77  路  4Comments

simplegroupware picture simplegroupware  路  5Comments

gustavohenke picture gustavohenke  路  4Comments