facebook/php-webdriver是一個很棒的客戶端硒和PHP。
您可以使用它來自動執行Web任務(如OP所需),或者您可以簡單地將php-webdriver集成到您的測試框架中。有一些項目已經提供了這一點:
安裝所有
下載並安裝facebook/php-webdriver。 composer require facebook/webdriver
Download Selenium &啓動它。 java -jar selenium-server-standalone-#.jar
Download Quick Java並將其放置到您的項目目錄中。
使用
在這個例子中,我們使用擴展quickjava
禁用除了javascript
和cookies
一切。
這裏
查看更多偏好設置:這裏
https://github.com/ThatOneGuyDotNet/QuickJava/blob/master/defaults/preferences/defaults.js
查看更多示例命令:
https://github.com/facebook/php-webdriver/wiki/Example-command-reference
use Facebook\WebDriver\Firefox\FirefoxProfile;
use Facebook\WebDriver\Firefox\FirefoxDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
// Change this to the path of you xpi
$extensionPath = $this->container->getParameter('kernel.root_dir').'/../bin/selenium/quickjava-2.0.6-fx.xpi';
// Build our firefox profile
$profile = new FirefoxProfile();
$profile->addExtension($extensionPath);
$profile->setPreference('thatoneguydotnet.QuickJava.curVersion', '2.0.6.1');
$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.Images', 2);
$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.AnimatedImage', 2);
$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.CSS', 2);
//$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.Cookies', 2);
$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.Flash', 2);
$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.Java', 2);
//$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.JavaScript', 2);
$profile->setPreference("thatoneguydotnet.QuickJava.startupStatus.Silverlight", 2);
// Create DC + Driver
$dc = DesiredCapabilities::firefox();
$dc->setCapability(FirefoxDriver::PROFILE, $profile);
$driver = RemoteWebDriver::create($host, $dc);
$driver->get('http://stackoverflow.com');
// Do stuff - https://github.com/facebook/php-webdriver/wiki/Example-command-reference
//$driver->findElement(WebDriverBy::id("element-id"));
// The HTML Source code
$html = $driver->getPageSource();
// Firefox should be open and you can see no images or css was loaded
[php-webdriver](https://github.com/facebook/php-webdriver)庫足夠簡單,使用[Steward](https://github.com)等工具可以更輕鬆地進行設置/ LMC-EU /管家)。我建議不要浪費時間使用Selenium IDE,只需在PHP中編寫所需的場景。 –