簡體   English   中英

使用 Firefox、Geckodriver 和 Perl 運行 Selenium 時出現問題

[英]Problem running Selenium with Firefox, Geckodriver and Perl

我在使用 Perl 的 Selenium::Remote::Driver 運行 Selenium 時遇到問題。

我在 Ubuntu 22 上使用 Selenium standalone 3.9.1 + Geckodriver 0.29.0 + Firefox 91.7.0esr

首先,我嘗試使用所有軟件的最新版本,但也出現了錯誤。 在另一台裝有 Centos 7 的機器上,所有這些軟件都運行良好,所以我決定將所有軟件降級到舊版本。

我已經從源代碼安裝了 Firefox,從我的 Centos 7 機器上下載了 Selenium 3.9.1(以確保它沒問題)並下載了 Geckodriver。

我使用此命令運行 Selenium 服務器(geckodriver 在同一文件夾中):

xvfb-run java  -Dwebdriver.gecko.driver=./geckodriver -jar selenium-server-standalone-3.9.1.jar

服務器正常啟動,但是當我嘗試運行我的 Perl 腳本時 - 它啟動並“凍結”在我創建新的 Selenium::Remote::Driver 對象的字符串處。

這是 Selenium 寫的:

xvfb-run java  -Dwebdriver.gecko.driver=./geckodriver -jar selenium-server-standalone-3.9.1.jar

21:01:29.989 INFO - Selenium build info: version: '3.9.1', revision: '63f7b50'
21:01:29.990 INFO - Launching a standalone Selenium Server on port 4444
2022-12-10 21:01:30.614:INFO::main: Logging initialized @1317ms to org.seleniumhq.jetty9.util.log.StdErrLog
2022-12-10 21:01:30.916:INFO:osjs.Server:main: jetty-9.4.7.v20170914, build timestamp: 2017-11-21T21:27:37Z, git hash: 82b8fb23f757335bb3329d540ce37a2a2615f0a8
2022-12-10 21:01:30.967:WARN:osjs.SecurityHandler:main: ServletContext@o.s.j.s.ServletContextHandler@76508ed1{/,null,STARTING} has uncovered http methods for path: /
2022-12-10 21:01:30.974:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@76508ed1{/,null,AVAILABLE}
2022-12-10 21:01:31.050:INFO:osjs.AbstractConnector:main: Started ServerConnector@94c87b{HTTP/1.1,[http/1.1]}{0.0.0.0:4444}
2022-12-10 21:01:31.051:INFO:osjs.Server:main: Started @1754ms
21:01:31.051 INFO - Selenium Server is up and running on port 4444
2022-12-10 21:01:43.601:INFO:osjshC.ROOT:qtp770189387-11: org.openqa.selenium.remote.server.WebDriverServlet-7f1302d6: Initialising WebDriverServlet
21:01:43.741 INFO - Found handler: org.openqa.selenium.remote.server.commandhandler.Status@18d81100
21:01:43.750 INFO - /status: Executing GET on /status (handler: Status)
21:01:43.779 INFO - Found handler: org.openqa.selenium.remote.server.commandhandler.BeginSession@7dd86e24
21:01:43.789 INFO - /session: Executing POST on /session (handler: BeginSession)
21:01:43.899 INFO - Capabilities are: Capabilities {acceptSslCerts: true, browserName: firefox, javascriptEnabled: true, version: }
21:01:43.900 INFO - Capabilities {acceptSslCerts: true, browserName: firefox, javascriptEnabled: true, version: } matched class org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.firefox.GeckoDriverService)
1670706103980   geckodriver     INFO    Listening on 127.0.0.1:16612
1670706104621   mozrunner::runner       INFO    Running command: "/usr/bin/firefox" "--marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofileRTGbtt"
[GFX1-]: glxtest: libEGL missing
1670706106386   Marionette      INFO    Marionette enabled
console.warn: SearchSettings: "get: No settings file exists, new profile?" (new NotFoundError("Could not open the file at /tmp/rust_mozprofileRTGbtt/search.json.mozlz4", (void 0)))
1670706150816   Marionette      INFO    Listening on port 36747
Exiting due to channel error.
Exiting due to channel error.
Exiting due to channel error.
21:02:45.425 INFO - HTTP Status: '500' -> incorrect JSON status mapping for 'timeout' (408 expected)

更新:我的 Perl 腳本的一部分,它凍結在字符串“my $driver = Selenium::Remote::Driver->new;”

#!/usr/bin/perl

use strict;
use warnings;

use utf8;

use DBI;
use Selenium::Remote::Driver;
use Data::Dumper;

binmode STDOUT, ":utf8";

print "Started parser at ".scalar(localtime)."\n\n";

my $dbh = DBI->connect("DBI:mysql:db", "user", "pass", {mysql_enable_utf8 => 1});

my $total_words = 0;

exit if !$ARGV[0];

my @dictionary = @ARGV;

print "Initial hashtag(s): ".join(" ", @dictionary)."\n\n";

my $driver = Selenium::Remote::Driver->new;

$driver->set_window_position(0, 0);
$driver->set_window_size(20000, 600, 'current');

……

更新 2:我已經從源代碼安裝了 Firefox 108,按照@HåkonHægland 的建議下載了 geckodriver 0.32.0 和 selenium 4.7.1。 但它仍然不起作用。

以下是輸出: 這是我嘗試運行 Perl 腳本時的輸出:

Could not create new session: Server returned error message read timeout at /usr/share/perl5/Net/HTTP/Methods.pm line 274.

這是我嘗試運行腳本時 Selenium-server 的輸出:

17:36:55.676 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "8206aa152f3c4da7260f4378969b94f1","eventTime": 1670953004537922002,"eventName": "exception","attributes": {"driver.url": "http:\u002f\u002flocalhost:13123","exception.message": "Error while creating session with the driver service. Stopping driver service: java.util.concurrent.TimeoutException\nBuild info: version: '4.7.1', revision: 'c6795baf1a3'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.0-1026-aws', java.version: '11.0.17'\nDriver info: driver.version: unknown","exception.stacktrace": "org.openqa.selenium.TimeoutException: java.util.concurrent.TimeoutException\nBuild info: version: '4.7.1', revision: 'c6795baf1a3'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.0-1026-aws', java.version: '11.0.17'\nDriver info: driver.version: unknown\n\tat org.openqa.selenium.remote.http.netty.NettyHttpHandler.makeCall(NettyHttpHandler.java:65)\n\tat org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42)\n\tat org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:56)\n\tat org.openqa.selenium.remote.http.netty.NettyHttpHandler.execute(NettyHttpHandler.java:49)\n\tat org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42)\n\tat org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:56)\n\tat org.openqa.selenium.remote.http.netty.NettyClient.execute(NettyClient.java:99)\n\tat org.openqa.selenium.remote.tracing.TracedHttpClient.execute(TracedHttpClient.java:55)\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:124)\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:106)\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)\n\tat org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:146)\n\tat org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:69)\n\tat org.openqa.selenium.grid.node.local.SessionSlot.apply(SessionSlot.java:147)\n\tat org.openqa.selenium.grid.node.local.LocalNode.newSession(LocalNode.java:379)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:645)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession(LocalDistributor.java:564)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest(LocalDistributor.java:818)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1(LocalDistributor.java:779)\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\n\tat java.base\u002fjava.lang.Thread.run(Thread.java:829)\nCaused by: java.util.concurrent.TimeoutException\n\tat java.base\u002fjava.util.concurrent.CompletableFuture.timedGet(CompletableFuture.java:1886)\n\tat java.base\u002fjava.util.concurrent.CompletableFuture.get(CompletableFuture.java:2021)\n\tat org.asynchttpclient.netty.NettyResponseFuture.get(NettyResponseFuture.java:206)\n\tat org.openqa.selenium.remote.http.netty.NettyHttpHandler.makeCall(NettyHttpHandler.java:59)\n\t... 21 more\n","exception.type": "org.openqa.selenium.TimeoutException","logger": "org.openqa.selenium.grid.node.config.DriverServiceSessionFactory","session.capabilities": "{\"acceptSslCerts\": true,\"browserName\": \"firefox\",\"javascriptEnabled\": true,\"platformName\": \"ANY\",\"version\": \"\",\"platform\": \"ANY\"}\n"}}

該解決方案對我來說非常出乎意料 - 我一直在使用 AWS EC2 並且在我增加 CPU 和 RAM 之后 - 一切都開始正常工作!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM