Chapters
23 Chapters
|
1:59:49
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: >=5.4.0, <7.3.0
Subscribe to download the code!Compatible PHP versions: >=5.4.0, <7.3.0
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
07.
Finding Elements by CSS and Name
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial uses a very old version of Symfony. The fundamentals of Behat are still valid, but integration with Symfony will be different.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=5.4.0, <7.3.0",
"symfony/symfony": "^2.7", // v2.7.4
"twig/twig": "^1.22", // v1.22.1
"sensio/framework-extra-bundle": "^3.0", // v3.0.16
"doctrine/doctrine-bundle": "^1.5", // v1.5.1
"doctrine/orm": "^2.5", // v2.5.1
"doctrine/doctrine-fixtures-bundle": "^2.2", // v2.2.1
"behat/symfony2-extension": "^2.0" // v2.0.0
},
"require-dev": {
"behat/mink-extension": "^2.0", // v2.0.1
"behat/mink-goutte-driver": "^1.1", // v1.1.0
"behat/mink-selenium2-driver": "^1.2", // v1.2.0
"phpunit/phpunit": "^4.8" // 4.8.18
}
}
14 Comments
I'm facing a weird problem with
findI have the following piece of code:$page = $this->getSession()->getPage();<br />var_dump($page->getContent());<br />var_dump($page->find('css', 'html'))The best thing is that the first var_dump prints HTML content of the page (with
<html></html>tags), but the latter returns null. When I change the function tofindAll- empty array is returned.I am using behat/behat 3.5.0, behat/gherkin 4.6.0, behat/mink 1.7.1, behat/mink-browserkit-driver 1.3.3, behat/mink-extension 2.3.1, and seleniumServer 3.141.59 with ChromeDriver 75.0.3770.100
Hey SirPL
Can you find any other element than HTML?
Which method can I use to fill the blanks on the web Page?
If you are using Mink (I believe you do), you can call the
fillField()methodCheers!
Looks like Mink can be good to make bots, and parsers?
Yea, it would be great for this - especially if you needed those bots to interact with pages that use JavaScript - that's a lot more powerful than just a parser that parses links and follows them :).
How to use CSS selectors when user Behat Drupal? I dont see a mink.php file in the root when installing, but behal.yml has Drupal\DrupalExtension\Context\MinkContext
Hey Johnatas,
I'm 99% sure it's the same! Actually, mink.php in this tutorial is just a playground. First of all, you need to get session, and then you can get the page from it. Try this in your Behat context file:
$page = $this->getSession()->getPage();
And then you can call find() method on $page as we do in this screencast.
Cheers!
Actually the page is completely different now. I'm getting the 1st link however clicking it via Selenium driver fails with "PHP Fatal error: Uncaught WebDriver\Exception\ElementNotVisible: element not visible" error.
I just think the page is refreshing because of ads which is causing the error.
Instead I started from the Wiki Activity page (no ads) and looked for the first link in the content area since it was still complaining about the secondary navigation links not being visible.
Hey Maria,
Ah, what a bummer! We're sorry for the inconvenience, but it was something not related from us directly. We're working on a fix for this and will update the code soon. Thanks for letting us know! Actually, not a big deal, you just need to use a different of "Wiki Activity" link, because this one is hidden (it's shown only when you hover over the "Explore" menu item). So, to follow our example, you can look for the first link in the menu which is "Books" and which is visible by default, you can easily find it with ".wds-tabs li a" selector, or just use:
Also, latest versions of Firefox (which is used by default) could not work properly, that's why I recommend to use Google Chrome instead as a Selenium2 driver, you can specify it as the first parameter to Selenium2Driver class:
Cheers!
They must have watched this tutorial... now the h1 is an h2... :(
Bah! The folly of using external sites. Thanks for the note!
I've updated the script + code blocks for this (code block will show up soon when its cache refreshes).
Thanks Pietrino!
no prob, happy to help and to learn ;)
"Houston: no signs of life"
Start the conversation!