Control Chrome or Chromium easily.
- PHP 7.4 or latest
- Laravel 8.x
- Chrome or Chromium latest version
You can install the package via composer:
composer require masga/laravel-chromedriver
use Facebook\WebDriver\WebDriverBy;
use Masga\ChromeDriver\Facades\Browser;
Route::get('/browser', function () {
Browser::start();
// Get driver
$driver = Browser::getDriver();
// Go to URL
$driver->get('https://en.wikipedia.org/wiki/Selenium_(software)');
// Find search element by its id, write 'PHP' inside and submit
$driver->findElement(WebDriverBy::id('searchInput')) // find search input element
->sendKeys('PHP') // fill the search box
->submit(); // submit the whole form
// Find element of 'History' item in menu by its css selector
$historyButton = $driver->findElement(
WebDriverBy::cssSelector('#ca-history a')
);
$btnText = $historyButton->getText();
// Terminate browser quickly. (optional)
// Browser::quit();
return 'About to click to a button with text: ' . $btnText;
});
Browser will quit automatically after the response is sent but you can quit quickly using
Browser::quit()
You can publish the config file using this command:
php artisan vendor:publish --tag=chromedriver-config
The MIT License. Please see License File for more information.