How to open a new tab in a firefox browser using selenium remote driver in perl scripting?

724 views Asked by At

I am trying to open new tab in firefox using selenium::Remote::Driver in perl language, i am using below code, i am getting error as"Can't call method "send_keys" on an undefined value at D:/workspace/SamplePerl_project/sample.pl line 9."can you please suggest me how to open a new tab or new window in firefox in perl language...please help me...thanks in advance..

**sample.pl**


use Selenium::Remote::Driver;
use Selenium::Remote::WDKeys;
my $driver = new Selenium::Remote::Driver;
 if(defined $driver)
{
  print "driver is defined";
  $driver->get("https://www.google.co.in/");
  $driver->set_implicit_wait_timeout(40000);
  #$driver->send_modifier('Ctrl','t');
  $driver->find_elements("body")->send_keys(KEYS->{'Ctrl','t'});
}

I am using send_keys method for that i got error as"Can't call method "send_keys" on an undefined value ",i am using send_modifier for that also i got error as"Error while executing command: Server returned error code 404 and no data at",please help me.

2

There are 2 answers

1
ddavison On

find_elements returns elements. Plural. You are unable to send_keys on an array of objects.

What you want is:

$driver->find_element("body")->send_keys(KEYS->{'Ctrl','t'}); # without the 's'
0
Thibaut Bultiaux On

This was working for me

$driver->execute_script("window.open('');");