Reputation: 37
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).
Upvotes: 0
Views: 1100
Reputation: 4173
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.
Upvotes: 1