【问题标题】:Error while using Selenium::Remote::Driver使用 Selenium::Remote::Driver 时出错
【发布时间】:2015-05-29 02:32:24
【问题描述】:

我正在尝试将 Perl 与 Selenium::Remote::Driver 模块一起使用。

我的代码:

use Selenium::Remote::Driver;
my $driver = Selenium::Remote::Driver->new('browser_name' => 'internet explorer',
                                           'port'         => '5555',
                                           'auto_close'   => 0);
$driver->get('http://www.google.com');
print $driver->get_title();
$driver->quit();

我收到此错误:

Could not connect to SeleniumWebDriver: Can't use string ("Command not found: GE
T /wd/hub/s"...) as a HASH ref while "strict refs" in use at C:/Perl/site/lib/Se
lenium/Remote/ErrorHandler.pm line 125.
 at C:/Perl/site/lib/Selenium/Remote/RemoteConnection.pm line 42.

知道怎么解决吗?

【问题讨论】:

  • 你在端口 5555 上有一个 selenium 集线器吗?您可以将浏览器指向它以检查
  • 我从我的代码中删除了端口,现在我收到了新错误-“无法创建新会话”
  • 我自己修好了。感谢您的帮助。
  • 那么你做了什么来修复它?
  • 您使用的是哪个版本的模块和 selenium webdriver?

标签: perl selenium selenium-webdriver


【解决方案1】:

对于使用 Perl 包 Selenium::Remote::Driver 的用户,此包与集线器模式不兼容。但是你可以很容易地让它像这样工作:打开文件 perl_root/Selenium/Remote/Commands.pm 并为例如此行返回的哈希中的每个 url 属性:

'status' => {
            'method'             => 'GET',
            'url'                => 'status',
            'no_content_success' => 0
        },

修改它:

'status' => {
            'method'             => 'GET',
            'url'                => 'wd/hub/status',
            'no_content_success' => 0
        },

现在您已经了解了它的工作原理,您可以修改 Driver.pm(或 Commands.pm)文件,例如更改方法 _execute_command 以更改处理命令的方式:无论我们是否在集线器中.. . 通过制作一个常量或任何您喜欢的东西(新对象属性、环境变量...),但您不能在不修改的情况下将此 Perl 包使用集线器模式。

问候,

【讨论】:

    【解决方案2】:

    它确实在那里说:

    在使用“strict refs”时,不能使用字符串 ... 作为 HASH。

    看看:

    Can't use string ("1") as a HASH ref while "strict refs" in use

    Can't use string as a hash ref..?

    【讨论】:

    • 你的意思是,pm 文件有错误。我如何解决它。我使用 ppm 安装 Selenium::Remote::Driver 模块
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 2016-06-23
    • 1970-01-01
    • 2020-02-27
    • 1970-01-01
    相关资源
    最近更新 更多