标签: php-webdriver

WebDriver 异常:无法找到 (POST) /wd/hub/session 的处理程序

Google Chrome 79.0.3945.130
ChromeDriver 79.0.3945.36
selenium-server-4.0.0-alpha-4.jar截至 2020 年 1 月 22 日,
来自 php-webdriver GitHub 的最新代码

我使用 Xfvb 在本地主机上以独立模式启动 Selenium 服务器,如下所示:

$ Xvfb :99 -screen 5 1920x1080x8 &
$ export DISPLAY=:99
$ java -Dwebdriver.chrome.driver="./chromedriver" -jar selenium-server-4.0.0-alpha-4.jar standalone
Run Code Online (Sandbox Code Playgroud)

然后我有一个测试助手类,它在 PHP 代码中启动:

    1 final public static function createWebDriver() {
    2   $options = new ChromeOptions();
    3   $options->addArguments(array('--window-size=1920,1080'));
    4   $caps= DesiredCapabilities::chrome();
    5   $caps->setCapability(ChromeOptions::CAPABILITY, $options);
    6   $driver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $caps);
    7   $driver->manage()->window()->maximize();
    8   return $driver;
    9}
Run Code Online (Sandbox Code Playgroud)

当我运行测试并调用 RemoteWebDriver::create() 函数时,它会引发异常:

Facebook\WebDriver\Exception\UnknownCommandException:无法找到(POST)/wd/hub/session /home/me/UnitTest/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:137 /home/me/UnitTest 的处理程序/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:380 /home/me/UnitTest/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:136 …

selenium webdriver selenium-chromedriver php-webdriver facebook-php-webdriver

6
推荐指数
1
解决办法
2万
查看次数

PHP 致命错误:未捕获的错误:找不到类“Facebook\WebDriver\ChromeOptions”

namespace Facebook\WebDriver;

use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;

require_once('vendor/autoload.php');

$host = 'http://localhost:4444/wd/hub';

$options = new ChromeOptions();
Run Code Online (Sandbox Code Playgroud)

我在创建类的对象时已阅读此链接,但ChromeOptions出现错误

PHP 致命错误:未捕获的错误:找不到类“Facebook\WebDriver\ChromeOptions”。

php selenium php-webdriver

4
推荐指数
1
解决办法
2350
查看次数

硒-如何等待?

我需要能够在采取某些措施之后等待页面可能发生的多种情况之一。这些示例包括:URL更改,设置了特定标题,页面上出现了某些内容,等等。

这说明了如何等待-https: //github.com/facebook/php-webdriver/wiki/HowTo-Wait。但是,我需要能够同时等待多件事。我希望在其中一种情况发生时停止等待。

是否有一种在等待期间进行“或”操作的方法(例如,等待URL更改标题包含“ foo” 页面上出现“栏”等)?

selenium php-webdriver

3
推荐指数
1
解决办法
1325
查看次数

如何通过 Facebook/php-webdriver 添加选项?

我正在寻求向 Facebook/php-webdriver 实例添加选项。

这可以获取初始选项:

$options = \Facebook\WebDriver\Remote\DesiredCapabilities::chrome();
Run Code Online (Sandbox Code Playgroud)

现在我想添加额外的选项:

$options->setCapability("enablePassThrough", FALSE);
$options->setCapability("no-sandbox", TRUE);
Run Code Online (Sandbox Code Playgroud)

我收到错误:

Call to undefined function setCapability()
Run Code Online (Sandbox Code Playgroud)

我已经尝试了几种方法,但尚未找到如何做到这一点。

向 Facebook/php-webdriver 实例添加选项的正确方法是什么?

selenium selenium-chromedriver selenium-webdriver php-webdriver facebook-php-webdriver

3
推荐指数
1
解决办法
3523
查看次数

如何在php-webdriver中滚动页面?

我正在尝试使用php-driver获取一些截图.而且看起来尽管拍摄了整个网页的图片,它只是拍摄显示在显示器/屏幕上的图片(这就是我们称之为屏幕截图的原因).

所以我的问题是如何捕获位于页面底部的图片?我们将页面滚动到指定的元素吗?或者有办法拍摄整个页面的图片?

这是我的截图代码:

    $host = 'http://localhost:4444/wd/hub'; // this is the default
    $capabilities = DesiredCapabilities::firefox();
    $webdriver = RemoteWebDriver::create($host, $capabilities, 5000);
    function find_image($url) {
        //Screenshot
        $GLOBALS["webdriver"]->get($url);
        $element = $GLOBALS["webdriver"]->findElement(WebDriverBy::cssSelector('#law > p > img'));
        $element_width = $element->getSize()->getWidth();
        $element_height = $element->getSize()->getHeight();
        $element_x = $element->getLocation()->getX();
        $element_y = $element->getLocation()->getY();
        $screenshot = __DIR__ . "/number/" . count($GLOBALS["data"]) . ".png";
        $GLOBALS["webdriver"]->takeScreenshot($screenshot);
        $src = imagecreatefrompng($screenshot);
        $dest = imagecreatetruecolor($element_width, $element_height);

        imagecopy($dest, $src, 0, 0, $element_x, $element_y, $element_width, $element_height);
        imagepng($dest, $screenshot);
        return convert_image($screenshot);
    }
Run Code Online (Sandbox Code Playgroud)

php selenium php-webdriver

0
推荐指数
1
解决办法
2316
查看次数