使用facebook
- PHP-Webdriver
自动化测试 ( 步骤请以github
上wiki
或者packagist
文档上为准 )
a、安装chrome
和chrome-driver
b、安装java
并下载selenium
的java server -- selenium-server-standalone-3.141.59
(独立服务器),访问localhost:4444/wd/hub
有响应标识成功
java -jar selenium-server-standalone-2.39.0.jar
c、下载扩展包 - 运行php脚本
{
"require": {
"facebook/webdriver": "^1.6.0"
}
}
d、获取cookie用户登录凭证
<?php
// 初始化
require_once('./vendor/autoload.php');
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverOptions;
// Selemium服务器
$host = 'http://localhost:4444/wd/hub'; // this is the default
$driver = RemoteWebDriver::create($host, DesiredCapabilities::chrome());
// 登录地址
$driver->get("http://127.0.0.1/index.php");
// 进入iframe
$driver->switchTo()->frame('aa');
// 进入登录表单iframe
$driver->switchTo()->frame('userLoginWindow_frame');
// 用户名
$driver->findElement(WebDriverBy::id("ext-comp-1005"))->sendKeys("root");
// 密码
$driver->findElement(WebDriverBy::id("ext-comp-1008"))->sendKeys("123456");
// 点击登录
$driver->findElement(WebDriverBy::id('ext-gen9'))->click();
// 获取cookie
$cookie = $driver->manage()->getCookies();
print_r($cookie);
各个下载地址:
chrome-driver
:
https://sites.google.com/a/chromium.org/chromedriver/
selenium-server
:
https://www.seleniumhq.org/download/
windows
- java
:
https://www.java.com/zh_TW/download/help/windows_manual_download.xml
composer
- php-web-driver
:
http://packagist.p2hp.com/packages/facebook/webdriver