I wrote some code with help from examples but when I run it I'm getting error in Ubuntu Server 12.04.2 LTS:
Failed to connect to , problem connecting to "localhost", port 4242: Connection refused at /usr/local/share/perl/5.14.2/MozRepl/Client.pm line 144
How can i fix this ?
#!/usr/bin/perl -w
use strict;
use WWW::Mechanize::Firefox;
use HTTP::Cookies;
my $username = "test";
my $password = "t3st";
my $mech = WWW::Mechanize::Firefox->new();
$mech->get("http://test.com/login.php"); print "Logging, Please Wait.\n";
$mech->submit_form(
form_number => 0,
fields => {
username => "$username",
password => "$password",
}
);
Install MozRepl firefox add-on on your firefox
Once installed, start the MozRepl in your firefox as below:
Tools->MozRepl->Start
Confirm that MozRepl is listening on port 4242 as below:
netstat -anp | grep firefox
tcp 0 0 127.0.0.1:4242 0.0.0.0:* LISTEN 1438/firefox
Good Luck !!
Note: I am not able to format this answer properly as SO formatting is not working as expected.
It is important to add to the answers above that since version 18, Firefox no longer displays the "Tools" menu unless you type the F10 key, or select "Options -> Menu bar".
Do you have the mozrepl plugin installed and enabled and configured for port 4242?
Related
EDITED AGAIN
I have a server on AWS somewhere in Northern Virginia and this is my monitoring server. I ssh into this Ubuntu server from another State to do system administration. I want to do web automation tests on this server which will test a web application on the Internet hitting a URL and verify that I can selenium test a login and authenticate successfully. This server is on an AWS cloud I'm not quite sure which Perl module to use since I'm accessing it remotely.
There are two CPAN modules: Selenium::Remote::Driver and WWW::Selenium. I have tried both and they are giving me issues. And I really don't know which is appropriate for my scenario. When I use Selenium::Remote::Driver, I get the following error:
Selenium server did not return proper status at /usr/local/share/perl/5.18.2/Selenium/Remote/Driver.pm line 401.
When I use WWW::Selenium, I get this error:
Failed to start new browser session: org.openqa.selenium.server.RemoteCommandException: Error while launching browser
I was able to launch firefox manually from the AWS monitoring server by exporting the DISPLAY but it was really slow. I have heard that I can use a headless browser but I would have to export the DISPLAY by:
export DISPLAY=:5
But remember, I'm sshing into this AWS/Selenium server from my desktop so I'm assuming I use the above command on the AWS/Selenium Server while I'm ssh into it from my desktop? Actually, at this point, I'm not sure I'm doing here. Can somebody help?
The problem in this type of questions is that the variety of configurations and binaries in your setup might be so broad that the it is hard to actually provide a straight and correct answer for YOUR SETUP.
This answer has the following assumptions:
you have downloaded the selenium-server-standalone.jar into /usr/lib/
you have jdk 1.8 ( run the java -version in the shell
you have installed and configured the xvfb-run ( it is a fight on it's own )
So :
```
# ssh to your server , obs the -X !
ssh -X user-name#server-name
# start the selenium-server-standalone on the server
xvfb-run -e /dev/stdout java -Dwebdriver.chrome.driver=/usr/bin/chromedriver -jar /usr/lib/selenium-server-standalone.jar &
# one liner test - this is one veery long one
perl -e 'use strict ; use warnings ; use Data::Printer ; my $host="127.0.0.1"; use Selenium::Remote::Driver;my $driver = Selenium::Remote::Driver->new( "browser_name" =>"chrome", "error_handler" => sub { print $_[1]; croak 'goodbye'; }, "remote_server_addr" => "$host","port"=> "4444");$driver->debug_on();$driver->get("http://www.google.com"); print $driver->get_title();$driver->quit();' &
```
Here is the code in the one-liner as a perl script
#!/usr/bin/env perl
use strict ;
use warnings ;
use Carp ;
use Data::Printer ;
use Selenium::Remote::Driver;
my $host="127.0.0.1";
my $driver = Selenium::Remote::Driver->new(
"browser_name" =>"chrome"
, "error_handler" => sub { print $_[1]; croak 'goodbye' ; }
, "remote_server_addr" => "$host"
, "port"=> "4444") ;
$driver->debug_on() ;
$driver->get("http://www.google.com");
print $driver->get_title();
$driver->quit();
The output should look something like:
```
Prepping get
Executing get
REQ: POST, http://127.0.0.1:4444/wd/hub/session/ddb9c2575ab026cdb8c640bdc554181b/url, {"url":"http://www.google.com"}
RES: {"sessionId":"ddb9c2575ab026cdb8c640bdc554181b","status":0,"value":null}
Prepping getTitle
Executing getTitle
REQ: GET, http://127.0.0.1:4444/wd/hub/session/ddb9c2575ab026cdb8c640bdc554181b/title, {}
RES: {"sessionId":"ddb9c2575ab026cdb8c640bdc554181b","status":0,"value":"Google"}
GooglePrepping quit
Executing quit
REQ: DELETE, http://127.0.0.1:4444/wd/hub/session/ddb9c2575ab026cdb8c640bdc554181b, {}
RES: {"sessionId":"ddb9c2575ab026cdb8c640bdc554181b","status":0,"value":null}
```
Try running the below code:
#!/usr/bin/perl
use warnings;
use strict;
use Selenium::Remote::Driver;
my $host = "10.10.1.1"; //Enter your server IP in this place
my $driver = new Selenium::Remote::Driver('remote_server_addr' => $host,
'port' => '4444',
'auto_close' => 0);
$driver->get('http://www.google.com');
I'm trying to connect me to a switch using SSH1 (the switch is old and does not support ssh2) and after the firsts steps, my program dosen't do nothing and i have to Ctrl+C to stop it
# Perl v5.8.8 built for MSWin32-x86-multi-thread
#!perl
use strict;
use warnings;
use Net::SSH::Perl;
my $host = "10.*.*.*";
my $username = "***";
my $password = "***";
my $cmd = 'show version';
my $ssh = Net::SSH::Perl->new($host, debug => 1);
$ssh->login($username, $password);
my($stdout, $stderr, $exit) = $ssh->cmd($cmd); #the script stops here
print $stdout;
logs :
Connecting to 10.*.*.*, port 22.
Remote version string: SSH-1.5-OpenSSH_2.9p1
Remote protocol version 1.5, remote software version OpenSSH_2.9p1
Net::SSH::Perl Version 1.42, protocol version 1.5.
No compat match: OpenSSH_2.9p1.
Connection established.
Waiting for server public key.
Received server public key (512 bits) and host key (896 bits).
Host '10.*.*.*' is known and matches the host key.
Encryption type: DES3
Sent encrypted session key.
Received encryption confirmation.
Trying password authentication.
Sending command: show version
Entering interactive session.
Terminating on signal SIGINT(2) #Ctrl-C
i can log me in with putty and it works.
I used wiresharck and we can see that the password and maybe the login are not used counter to putty http://image.noelshack.com/fichiers/2016/31/1470038197-troubleshooting2-ssh1.png, packets are too lights.
I don't understand what's going wrong, why the connection failed and logs say nothing about it.
It seems that it's a problem about my 3 HP switch (2524,5304, 5130). I finally tested on a cisco switch and it works perfeclty........
I will search a solution in they key size or something like that
Edit : i'm using python now and its the same problem but i found the solution here http://forums.juniper.net/t5/ScreenOS-Firewalls-NOT-SRX/Python-Paramiko-with-netscreen/m-p/294864
I have written a simple Perl script to launch google. But it terminates with an error - Could not connect to SeleniumWebDriver at C:/perl/lib/Selenium/Remote/Driver.pm line 220
I am using selenium server version - 2.31
OS - windows7 (32 bit)
Perl Code
use warnings;
use strict;
use Selenium::Remote::Driver;
my $driver = Selenium::Remote::Driver->new( browser_name => 'firefox', port => 4444,
platform => 'ANY');
$driver->get('http://www.google.com');
sleep(5);
print $driver->get_title();
$driver->quit();
When i execute perl script, at each instance, on server command prompt i could see this line -
14:07:23.325 INFO - Executing: org.openqa.selenium.remote.server.handler.Status#
8e96fc at URL: /status)
14:07:23.327 INFO - Done: /status
But browser is not getting launched. Please can anybody help me about the issue?
Did you start the selenium server on a machine with firefox and X (assuming Linux)
and maybe add the proxy in
{remote_server_addr=>'localhost', port=>4444,proxy => { 'proxyType' => 'system' }}
can you post how you're starting selenium
I started the selenium server using command
"java -jar selenium-server-standalone-2.31.0.jar"
But the issue get resolved now. I guess it was Perl issue. I was using Active Perl V 5.16.
Then i installed Strawberry Perl V 5.18 and it worked.
Thank you!
I don't know why but I cannot launch browser using the below code. I am using EPIC on eclipse. I have installed required selenium modules for this.
I get this error when I run below mentioned code: "Could not connect to SeleniumWebDriver at C:/ProgramFiles/Perl/site/lib/Selenium/Remote/Driver.pm line 220"
Any help is appreciated.
Here is my code:
use Selenium::Remote::Driver;
my $driver = new Selenium::Remote::Driver(browser_name => 'firefox', port => 5555,
platform => 'WINDOWS');
$driver->get('http://www.google.com');
print $driver->get_title();
$driver->quit();
It might be closing the page before you notice it? Also, I think by default the port number selenium listens on is 4444.
Try this:
use Selenium::Remote::Driver;
my $driver = new Selenium::Remote::Driver(browser_name => 'firefox', port => 4444,
platform => 'ANY',);
$driver->get('http://www.google.com');
sleep(200);
print $driver->get_title(),"\n";
$driver->quit();
I changed the Selenium version to 2.31 and it worked. Previously I was using 2.28 which had incompatibility with FF 19
Charles, my PC was updated with new Java version and so my server start up file was failing to start the server. I corrected the start up file with correct java path and it launches the browser.
But I don't know why it gives blank page as it should open google.com
before run the code you should start the remote server.
Enter the path as below where your chrome driver and jar file are exited in your system and
Go to the command prompt an run the following command- please
java -Dwebdriver.chrome.driver="\Enter folder path\chromedriver.exe" -jar \Enter folder path\selenium-server-standalone-2.53.0.jar
and if you are using Firefox then write the following code.
my $driver = Selenium::Remote::Driver->new();
for chrome user following -
my $driver = Selenium::Remote::Driver->new(browser_name => 'chrome');
I'm trying to develop a Web app in Perl using Hypertable. Sample code:
#!/usr/bin/perl -w
use strict;
use warnings;
use CGI;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
use CGI::Session ('-ip_match');
use Hypertable::ThriftClient;
use Data::Dumper;
my $q = new CGI;
print $q->header(-cache_control => "no-cache, no-store, must-revalidate");
eval {
my $client = new Hypertable::ThriftClient("localhost", 38080);
my $namespace = $client->open_namespace("glinpe");
my $result = $client->hql_exec($namespace, "select * from words where row=\"maths\" keys_only");
};
if ($#) {
if ($#->isa('Thrift::TException')) {
print Dumper($#);
} else {
print Dumper($#);
}
}
print "<h1>works</h1>";
The problem is when trying to execute from a web browser I get an error:
$VAR1 = bless( { 'code' => 0, 'message' => 'TSocket: Could not connect to localhost:38080 (Permission denied)' }, 'Thrift::TException' );
The scripts works properly when running from a terminal(under apache user), and as well in a browser if remove all Hypertable code.
I have 38080 port opened in iptables:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 38080 -j ACCEPT
OS: Centos 5.6.
The error message says you're missing permission, so that would be the answer (user apache, doesn't have permission to create socket to localhost:38080)
update: to elaborate, when you run it from a terminal, it is running as a regular user, but when apache runs it, most often it is running under apache user account, which may not have permission to open sockets
It could be you're using SELinux in which case see 'man chcon'
or search for "SELinux tutorial: Configuring RHEL 5 and Web servers"
OK, so there is two solution to this particular problem:
1. disable selinux - change configuration in /etc/selinux/config
2. run command:
setsebool -P httpd_can_network_connect 1
Thanks to previous answer for putting me back on track.