0

When I am using mink selenium2 driver I am unable to traverse the page. For example this chunk of code (and any other find* function) gives me an error message:

PHP Fatal error: Call to a member function getOuterHtml() on null in ...

public function test() 
{
    $this->seleniumSession->visit($this->websiteAddress);

    $page = $this->seleniumSession->getPage();

    echo $page->findById('feedback_button')->getOuterHtml();
}

On the other hand, when I am using Goutte driver session in the same chunk of code I get the HTML. (with no error message)

This is how I am creating Selenium2Driver:

    $this->seleniumDriver = new Selenium2Driver('firefox', array(
        'browserName'       => 'firefox',
        'version'           => '',
        'platform'          => 'ANY',
        'browserVersion'    => '56.0',
        'browser'           => 'firefox',
        'name'              => 'Behat Test',
        'deviceOrientation' => 'portrait',
        'deviceType'        => 'tablet',
        'selenium-version'  => '3.6.0'
    ), 'http://localhost:4444/wd/hub');

I am using selenium standalone server, version 3.6.0. I have also noticed that echo $page->getContent(); with Selenium2 Driver gives me more HTML than with Goutte driver (some additional script blocks that are not in the real web page source).

Sauron1953
  • 37
  • 7

1 Answers1

1

Goutte does not support JavaScript, the response will contain the entire page.

Selenium2Driver has support for JavaScript and you need to wait for the page to be loaded since some elements might be available later, the support for JS could be the reason you are getting more code.


You should avoid using calls like this $page->findById('feedback_button')->getOuterHtml(); since the findById method will return null if the element is not found and calling a method on a null will result in PHP Fatal error

You need to make sure the element is visible, implement a method to wait for it or just simply if the find method returns null throw some exception else do what you have to do.

lauda
  • 4,153
  • 2
  • 14
  • 28
  • I tried to wait (inserted `$this->seleniumSession->wait(5000);` after visiting the page). The same error about NULL appears. With Goutte I get ``. It's weird that I can actually see that element when I echo the page content (with Selenium2). – Sauron1953 Oct 13 '17 at 11:17
  • Try to increase the wait or use breakpoint to identify and debug the issue.See here a wait method https://stackoverflow.com/questions/38200240/behat-selenium-2-wait-for-page-to-load Also to avoid fatal exception https://stackoverflow.com/questions/43861931/behat-fillfield-xpath-giving-error – lauda Oct 13 '17 at 11:19
  • Eh, none of this stuff didn't make my code work. I switched from firefox to chrome (selenium standalone server -> chrome driver) and it solved the error. But, thanks on your tips. – Sauron1953 Oct 21 '17 at 08:08