minkphp / MinkZombieDriver

Zombie.js driver for Mink framework
41 stars 49 forks source link

Cannot read property 'nodeType' of null #150

Open vanderlee opened 8 years ago

vanderlee commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

@vanderlee , any update?

stof commented 8 years ago

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

fefas commented 7 years ago

Same problem hier.

stof commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

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

fefas commented 7 years ago

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 commented 7 years ago

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.