Selenium send_keys_ok method unknown in Perl

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
dlukinski
Posts: 1130
Joined: Tue Oct 06, 2015 9:42 am

Selenium send_keys_ok method unknown in Perl

Post by dlukinski »

Hello XI support

we've used sendKeys command in IDE to trigger "ENTER" button, which worked fine for HTML script.

However once exported and cleaned, WWW::Selenium is unable to run this command:

UNKNOWN: ok 1 - set_timeout, 120000
ok 2 - open, /share/page/
ok 3 - type, id=page_x002e_components_x002e_slingshot-login_x0023_default-username, nagximon
ok 4 - type, id=page_x002e_components_x002e_slingshot-login_x0023_default-password, C0mplexNagMon123
ok 5 - click, id=page_x002e_components_x002e_slingshot-login_x0023_default-submit-button
ok 6 - wait_for_page_to_load, 120000
ok 7 - type, css=input.alf-search-box-text, 53202206
Can't locate object method "send_keys" via package "Test::WWW::Selenium" (also tried "WWW::Selenium") at /usr/local/share/perl5/Test/WWW/Selenium.pm line 100
1..7
# Looks like your test exited with 255 just after 7.

Code: Select all

use strict;
use warnings;
use Time::HiRes qw(sleep);
use Test::WWW::Selenium;
use Test::More "no_plan";
use Test::Exception;
use TimePerf2;

my $time= TimePerf2->new(60,90,120);


my $sel = Test::WWW::Selenium->new( host => "10.x.x.114",.
                                    port => 4444,.
                                    browser => "*firefox",.
                                    browser_url => "http://alfresco.konecranes.com/" );

$time->startTime("ALL");
$sel->set_timeout_ok("120000");
if ( !  $sel->open_ok("/share/page/") ) {print "Location: " . $sel->get_location() . "\n";}
elsif ( ! $sel->set_speed("1500") ) { }

elsif ( !  $sel->type_ok("id=page_x002e_components_x002e_slingshot-login_x0023_default-username", "nagximon") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( !  $sel->type_ok("id=page_x002e_components_x002e_slingshot-login_x0023_default-password", "mypassword") ) {print "Location: " . $sel->get_location() . "\n";

elsif ( !  $sel->click_ok("id=page_x002e_components_x002e_slingshot-login_x0023_default-submit-button") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( ! $sel->wait_for_page_to_load_ok("120000") ) {}.
elsif ( !  $sel->type_ok("css=input.alf-search-box-text", "53202206") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( !  $sel->send_keys_ok("css=input.alf-search-box-text", "\${KEY_ENTER}") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( ! $sel->wait_for_page_to_load_ok("120000") ) {}.
elsif ( !  $sel->click_ok("//div[\@id='search-result-table']/div/table/tbody/tr[4]/td[5]/a[2]/span") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( ! $sel->wait_for_page_to_load_ok("120000") ) {}.
elsif ( !  $sel->click_ok("id=HEADER_USER_MENU_POPUP_text") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( !  $sel->click_ok("id=HEADER_USER_MENU_LOGOUT_text") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( ! $sel->wait_for_page_to_load_ok("120000") ) {}.
elsif ( !$time->endTime("ALL") ) { }

else { $time->getTimes(); }
$sel->stop();
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Selenium send_keys_ok method unknown in Perl

Post by mcapra »

Doesn't look like send_keys is included in the WWW::Selenium package. This is likely a failure on the part of the "Selenium IDE Perl Formatter" extension. type_keys seems to be a close alternative.

From: http://search.cpan.org/~mattp/Test-WWW- ... pm#METHODS
Former Nagios employee
https://www.mcapra.com/
dlukinski
Posts: 1130
Joined: Tue Oct 06, 2015 9:42 am

Re: Selenium send_keys_ok method unknown in Perl

Post by dlukinski »

mcapra wrote:Doesn't look like send_keys is included in the WWW::Selenium package. This is likely a failure on the part of the "Selenium IDE Perl Formatter" extension. type_keys seems to be a close alternative.

From: http://search.cpan.org/~mattp/Test-WWW- ... pm#METHODS
It fails to send "ENTER" to the element after correctly typing the search string

What do you use / how to send keyboard keys to web elements in cpan/perl/Selenium case?
Could you please provide perl examples which would work for NAGIOS XI perl ?
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Selenium send_keys_ok method unknown in Perl

Post by mcapra »

Try replacing line 31:

Code: Select all

elsif ( !  $sel->send_keys_ok("css=input.alf-search-box-text", "\${KEY_ENTER}") ) {print "Location: " . $sel->get_location() . "\n";}
With this one of these two options:

Code: Select all

elsif ( !  $sel->type_keys("css=input.alf-search-box-text", "\${KEY_ENTER}") ) {print "Location: " . $sel->get_location() . "\n";}

# or this

elsif ( !  $sel->key_press("css=input.alf-search-box-text", "\${KEY_ENTER}") ) {print "Location: " . $sel->get_location() . "\n";}
And let me know what the resulting behavior/output is. Enter is a tricky key because it's possible that Perl and the Selenium server are processing the character differently.

You might also try separating the element and sending keys to it directly (keeping in mind this will break the elsif chain):

Code: Select all

my $element = $sel->find_element("css=input.alf-search-box-text");
$element->send_keys("\${KEY_ENTER}");
$element->submit();
Former Nagios employee
https://www.mcapra.com/
dlukinski
Posts: 1130
Joined: Tue Oct 06, 2015 9:42 am

Re: Selenium send_keys_ok method unknown in Perl

Post by dlukinski »

mcapra wrote:Try replacing line 31:

Code: Select all

elsif ( !  $sel->send_keys_ok("css=input.alf-search-box-text", "\${KEY_ENTER}") ) {print "Location: " . $sel->get_location() . "\n";}
With this one of these two options:

Code: Select all

elsif ( !  $sel->type_keys("css=input.alf-search-box-text", "\${KEY_ENTER}") ) {print "Location: " . $sel->get_location() . "\n";}

# or this

elsif ( !  $sel->key_press("css=input.alf-search-box-text", "\${KEY_ENTER}") ) {print "Location: " . $sel->get_location() . "\n";}
And let me know what the resulting behavior/output is. Enter is a tricky key because it's possible that Perl and the Selenium server are processing the character differently.

You might also try separating the element and sending keys to it directly (keeping in mind this will break the elsif chain):

Code: Select all

my $element = $sel->find_element("css=input.alf-search-box-text");
$element->send_keys("\${KEY_ENTER}");
$element->submit();
First line results: ENTER not pressed (cursor stays in the entry filed)

Second line line results:

ERROR: invalid keySequence (exists browser after executing that line)

Code: Select all

[root@fikc-nagxidev01 libexec]# perl alfresco-3-perl
ok 1 - set_timeout, 120000
ok 2 - open, /share/page/
ok 3 - type, id=page_x002e_components_x002e_slingshot-login_x0023_default-username, nagximon
ok 4 - type, id=page_x002e_components_x002e_slingshot-login_x0023_default-password, C0mplexNagMon123
ok 5 - click, id=page_x002e_components_x002e_slingshot-login_x0023_default-submit-button
ok 6 - wait_for_page_to_load, 120000
ok 7 - type, css=input.alf-search-box-text, 53202206
Error requesting http://10.96.36.114:4444/selenium-server/driver/:
ERROR: invalid keySequence
1..7
# Looks like your test exited with 255 just after 7.
[code/]

Last advice:

unsure because previously you told me that lines in the clean WWW::Selenium Perl should start from elsif or if..
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Selenium send_keys_ok method unknown in Perl

Post by mcapra »

Third option doesn't seem to matter anyway:

Code: Select all

Can't locate object method "find_element" via package "Test::WWW::Selenium" (also tried "WWW::Selenium")
I was able to do this successfully in Java, Python, and Ruby using their respective Selenium libraries. For whatever reason, Perl is unable to do this right.

If the css=input.alf-search-box-text element is part of a <form> element, you might try submitting that <form> directly (using Selenium's submit command) rather than trying to click a specific button or press a specific key in a specific field.
Former Nagios employee
https://www.mcapra.com/
dlukinski
Posts: 1130
Joined: Tue Oct 06, 2015 9:42 am

Re: Selenium send_keys_ok method unknown in Perl

Post by dlukinski »

mcapra wrote:Third option doesn't seem to matter anyway:

Code: Select all

Can't locate object method "find_element" via package "Test::WWW::Selenium" (also tried "WWW::Selenium")
I was able to do this successfully in Java, Python, and Ruby using their respective Selenium libraries. For whatever reason, Perl is unable to do this right.

If the css=input.alf-search-box-text element is part of a <form> element, you might try submitting that <form> directly (using Selenium's submit command) rather than trying to click a specific button or press a specific key in a specific field.

Hi again

We found key_press_native working in this case
So I think we could close this thread now

Thank you
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Selenium send_keys_ok method unknown in Perl

Post by mcapra »

Closing this up, feel free to continue the discussion in your recent thread if there's additional issues!
Former Nagios employee
https://www.mcapra.com/
Locked