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

Cannot read property 'nodeType' of null #150

Open
vanderlee opened this issue Jan 13, 2016 · 12 comments
Open

Cannot read property 'nodeType' of null #150

vanderlee opened this issue Jan 13, 2016 · 12 comments

Comments

@vanderlee
Copy link

I get the following error using the Zombie driver:

Error "Cannot read property 'nodeType' of null" while executing code: var node,
      refs = [],
      result = browser.xpath("\/\/html");

  while (node = result.iterateNext()) {
      if (node.nodeType !== 10) {
          pointers.push(node);
          refs.push(pointers.length - 1);
      }
  }
  stream.end(JSON.stringify(refs)); (Behat\Mink\Exception\DriverException)

Using Zombie 4.2.1 and Mink 1.7.0 with zombie-driver 1.3.0.
I also tried Zombie 4.0.13 to check if this was a regression, but both versiions give the same error.

The weird thing is, it only happens for a specific .find() statement:
These works fine:

$page->find('css', '#username');
$page->find('css', '#password');

These fail:

$page->find('css', 'html');
$page->getHtml();

These all worked just fine using the Goutte driver.

I tried changing the javascript a bit to find the problem, but I can't find it.

If I change the line stream.end(JSON.stringify(refs)); to stream.end(JSON.stringify([])); or stream.end('[]');, I no longer get this error. I get an error that there are no matches, but that's to be expected. Seems like the problem is in stream.end().

@aik099
Copy link
Member

aik099 commented Jan 14, 2016

Are you using IO.JS to run Zombie?

The Zombie 4.x+ require IO.JS to work and would crash with strange errors when executed on NodeJS.

If you're running IO.JS, then please post:

  1. HTML of the page you're using
  2. complete PHP example (including creation of driver and visiting the page)

Also try using Zombie 3 and report if that works in there.

@vanderlee
Copy link
Author

I'm using the current stable Node.js, v4.2.4.

The HTML is the same as https://test.iconneqt.nl/admin/index.php, except on localhost

Will try to post a PHP example when I can get to the code (it's part of a much larger testing framework, so it might take a while to extract it). There is nothing much going on though; just loading an URI, getting the page, a few .find() statements on ID's, then the .getHtml() that fails.

@aik099
Copy link
Member

aik099 commented Jan 14, 2016

On the Node 5.4.1 and Zombie 4.2.1 the following snippet works fine for me:

$session = $this->getSession();
$session->visit('https://test.iconneqt.nl/admin/index.php');

$page = $session->getPage();

echo $page->getHtml();

Due the nature of implementation of getHtml method for Zombie )the .innerHTML is returned) and therefore it doesn't contain the <html> node itself and it's attributes.

$page->find('css', 'html');

This won't find any elements, because $page itself has //html xpath and therefore attempting to find tag with html name in it builds up//html/html selector which finds nothing.

@aik099
Copy link
Member

aik099 commented Jul 3, 2016

@vanderlee , any update?

@stof
Copy link
Member

stof commented Jul 4, 2016

$node->getHtml() returns the inner HTML for all drivers. This is why we have getOuterHTML

@fefas
Copy link

fefas commented Mar 7, 2017

Same problem hier.

@stof
Copy link
Member

stof commented Mar 8, 2017

please provide a reproducing case (best way is to build it as a testcase in the driver testsuite, but this is not required as long as the reproducing case is self-contained to allow us to include it in the testsuite)

@TerjeBr
Copy link

TerjeBr commented Mar 9, 2017

I got the same problem when the base_url was http://localhost and no web server was running on localhost.

It seems that when you get an empty response, this error is triggered when you try to do $page->getHtml();

It took me forever to find out what was wrong, because this bug masked what was my real issue.

@fefas
Copy link

fefas commented Mar 9, 2017

Hello @stof, the application is running in a docker container that is behind a nginx proxy that is also another docker container.

There is some problems to use zombie in this environment, but I can not see the problem read property 'nodeType' of null anymore. I made some changes and right now I am having others issues. In this way, I can not reproduce the problem I said.

I am still studying how to setup the our features tests correctly. If I continue with problems, I will post the details here or in a new issue.

Thank you!

@TerjeBr
Copy link

TerjeBr commented Mar 9, 2017

And the error happens in browser.xpath("\/\/html")

The while loop below it never gets executed, that is a red herring.

@fefas
Copy link

fefas commented Mar 9, 2017

For me, the problem also occurred using the method xpath, but with a more complex string parameter when I used the When I press "my-button" step (from behat/mink-extension).

@TerjeBr, did you check if the page was correctly loaded? I use the step Then print last response to check if the request made by zombie worked.

@TerjeBr
Copy link

TerjeBr commented Mar 9, 2017

No, my page was not loaded at all, because the local web-server was not running.

But I could not see that because it was masked by this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants