简体   繁体   English

如何通过selenium更改phantomjs的日志文件路径?

[英]How to change the logfile path of phantomjs through selenium?

i ran into a problem that seems to be a bug in selenium but maybe someone can hint me to a solution anyway. 我遇到了一个似乎是硒中的错误的问题,但也许有人可能会暗示我找到解决方案。

A similar question has been asked 11 months ago see: How can I change logfile path of phantomjs with selenium? 11个月前曾问过一个类似的问题,请参阅: 如何使用selenium更改phantomjs的logfile路径? but it was not solved. 但它没有解决。

I'm using Selenium::Remote::Driver in Perl to connect to selenium. 我在Perl中使用Selenium :: Remote :: Driver连接到selenium。 My code looks like this: 我的代码看起来像这样:

    my $driver = new Selenium::Remote::Driver(
    'remote_server_addr' => 'localhost',
    'port' => "4444",
    'browser_name' => 'phantomjs',

    extra_capabilities => {
        'phantomjs.cli.args' => ['--webdriver-logfile=/tmp/phantomjsdriver.log']
    }
);

I found out that the phantomjs devs have integrated the parameter phantomjs.cli.args to pass parameters through to phantomjs. 我发现phantomjs devs已经集成了参数phantomjs.cli.args来将参数传递给phantomjs。 The parameters show up but unfortunately are added to the default parameters. 参数显示但不幸的是被添加到默认参数。

See the logfile of selenium: 查看selenium的日志文件:

10:20:29.207 INFO - Creating a new session for Capabilities [{platform=ANY, javascriptEnabled=true, acceptSslCerts=true, phantomjs.cli.args=[--webdriver-logfile=/tmp/phantomjsdriver.log], browserName=phantomjs, version=}]
10:20:29.208 INFO - executable: /usr/local/node/bin/phantomjs
10:20:29.208 INFO - port: 5710
10:20:29.208 INFO - arguments: [--webdriver-logfile=/tmp/phantomjsdriver.log, --webdriver=5710, --webdriver-logfile=/phantomjsdriver.log]
10:20:29.208 INFO - environment: {}
PhantomJS is launching GhostDriver...
Unable to open file '/phantomjsdriver.log'

On the 4th line you can see that my argument was passed but the default '--webdriver-logfile=/phantomjsdriver.log' is also part of the arguments. 在第4行,您可以看到我的参数已通过,但默认的'--webdriver-logfile = / phantomjsdriver.log'也是参数的一部分。

I tried also to set the loglevel to NONE but it tries to open the logfile anyways. 我还尝试将loglevel设置为NONE,但它仍尝试打开日志文件。

Lastly i tried to start phantomjs with a config file but i couldn't figure out the config option for the logfile and i'm not sure that would help. 最后我试图用配置文件启动phantomjs但我无法弄清楚日志文件的配置选项,我不确定这会有所帮助。

My selenium server runs as a daemon if that is important. 我的selenium服务器作为守护进程运行,如果这很重要的话。

Any help is appreciated! 任何帮助表示赞赏!

Have a nice day 祝你今天愉快

Have you tried using new_from_caps method for full control of your driver instance? 您是否尝试过使用new_from_caps方法来完全控制驱动程序实例? Using this option no defaults are assumed by the constructor. 使用此选项,构造函数不会采用默认值。

eg 例如

my $driver = Selenium::Remote::Driver->new_from_caps( desired_capabilities => { 'browserName' => 'phantomjs', 'phantomjs.cli.args' => ['--webdriver-logfile=/tmp/phantomjsdriver.log'] } );

See doc here: https://metacpan.org/pod/Selenium::Remote::Driver#new_from_caps 请参阅此处的doc: https//metacpan.org/pod/Selenium :::Remote :: Driver#new_from_caps

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM