Page 2 of 2

Re: SELENIUM clickandWait or Timeout or else

Posted: Wed Jun 22, 2016 8:20 am
by spurrellian
Hi,

The below code successfully logs into an office 365 portal and then sign outs again using Nagios/selenium. You have to put in

Code: Select all

elsif ( ! $sel->pause("5000") ) {}
otherwise the script will fail

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 => "seleniumserver",
                                    port => 4444,
                                    browser => "*iexplore",
                                    browser_url => "https://login.microsoftonline.com/" );

$time->startTime("ALL");
$sel->set_timeout_ok("120000");
if ( !  $sel->open_ok("/login.srf?wa=wsignin1.0&rpsnv=4&ct=1466600682&rver=6.7.6640.0&wp=MCMBI&wreply=https%3a%2f%2fportal.office.com%2flanding.aspx%3ftarget%3d%252fdefault.aspx&lc=1033&id=501392&msafed=0&client-request-id=71451f75-cfce-44f2-a2df-379b53ddc6c4") ) {print "Location: " . $sel->get_location() . "\n";}
elsif ( ! $sel->set_speed("1500") ) { }

elsif ( ! $sel->pause("5000") ) {}

elsif ( !  $sel->type_ok("id=cred_userid_inputtext", "[email protected]") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( ! $sel->pause("5000") ) {}

elsif ( !  $sel->type_ok("id=passwordInput", "passwordforaccount") ) {print "Location: " . $sel->get_location() . "\n";}

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

elsif ( ! $sel->wait_for_page_to_load_ok("120000") ) {}

elsif ( !  $sel->click_ok("css=div.tiles-section.section") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( !  $sel->click_ok("xpath=(//button[\@type='button'])[10]") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( !  $sel->click_ok("//a[\@id='O365_SubLink_ShellSignout']/div/span[2]") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( ! $sel->wait_for_page_to_load_ok("120000") ) {}

elsif ( !$time->endTime("ALL") ) { }

else { $time->getTimes(); }
$sel->stop();

Re: SELENIUM clickandWait or Timeout or else

Posted: Wed Jun 22, 2016 8:29 am
by dlukinski
mcapra wrote:If the button exists within an iframe, selecting the iframe before interacting with the element is something you could try. eg, if the button is nested in an iframe like so:

Code: Select all

<iframe id="myCoolFrame" name="myCoolFrame">
           <a href="http://www.google.com">Lets Go To Google</a>
</iframe>
In order to click the "Lets Go To Google" link, you (in some cases) would need to first select the iframe "myCoolFrame". In the Selenium IDE, it would look something like this:

Code: Select all

.....
selectFrame            myCoolFrame
click                  link=Lets Go To Google
.....
You might also try selecting the current window:

Code: Select all

.....
selectWindow           title=My Window's Title
click                  link=Lets Go To Google
.....
Just a few considerations. Those might not be applicable to your current situation. As I do not know what the page immediately following "https://login.microsoftonline.com/" contains (I assume its a protected portal), I cannot offer much insight into why your test case is failing.

All I can say is that # ERROR: Element id=submitButton not found means that Selenium is unable to find an element with the id "submitButton" for some reason. There's lots of reasons why that check might fail, but I can't say for sure without knowing the structure of the page. If its a protected portal, I hardly expect that knowledge to be given to me ;)
I ended up removing last step (#10) from the script. Remainder worked. These are no easy portals to monitor (Microsoft Online services)

Re: SELENIUM clickandWait or Timeout or else

Posted: Wed Jun 22, 2016 9:02 am
by mcapra
I'm glad you were able to find a solution! Is it alright if we lock this thread and mark the issue as resolved?

Re: SELENIUM clickandWait or Timeout or else

Posted: Thu Jun 23, 2016 2:39 pm
by dlukinski
mcapra wrote:I'm glad you were able to find a solution! Is it alright if we lock this thread and mark the issue as resolved?
Yes please close (there will be 2 more attempts involving same portal and more steps, so there always a chance open new one:)