http://www.perlmonks.org?node_id=809772


in reply to Re^4: Using WWW::Selenium To Test Or Automate An Ajax Website
in thread Using WWW::Selenium To Test Or Automate An Ajax Website

Thanks for the tips! I finally figured it all out except for the class path stuff (I have no idea how to create a java classpath to the .jar file) but I eventually experimented until I figured out that I can run one terminal running selenium rc and open another terminal and run my perl code from that.

Low and behold my perl code comes to life and firefox loads up... only to die time and time again with a popup box that loads when you click 'login' on the website I'm trying to automate access to. After spending a whole day learning about how you need to select the popup box and close it, then select 'null' to get back to the original browser window I just can't seem to get my perl/selenium code to do what I want. The main issue is that upon clicking the 'logon' link at the website I'm trying to automate access, it is random event where by:

  1. No popup box pops up, or
  2. A popup box named 'stealth' pops up, or
  3. A popup box named 'entry' pops up.

I found that selenium is very fragile when it comes to coding the next step for it to preform... if I run my code without any mention to a popbox then everything is fine, but when I run the code and a popup box happens then it dies with a "255" exit message. Looking around the options in the IDE I couldn't see any program flow commands for selenium IDE so after going to the selenium website it seemed to me that program flow must come from the coding language you are using.

So I thought, ok, Perl has program flow commands, why not use the "if" statement and "elseif" and "else" for all three possibilities:

  1. no popup
  2. popup "stealth"
  3. popup "entry".

I coded it up as best as I could in Perl but then I got syntax errors where my blocks where. I was under the impression that something like $sel->title_is("Entry") would give perl a 'true' or 'false' and operate the program flow accordingly. Please help, I'm quite confused, a sample of the code is below:

my $sel = Test::WWW::Selenium->new( host => "localhost", port => 4444, browser => "*chrome", browser_url => "http://www.example +.com/" ); $sel->start(); $sel->set_timeout("60000"); $sel->open("/home/index.jsp"); $sel->click("link=Log in"); $sel->wait_for_page_to_load("60000"); if ($sel->title_is("Entry")) { $sel->select_window("entry"); $sel->close(); $sel->select_window("null"); } else ($sel->title_is("Stealth")) { $sel->select_window("stealth"); $sel->close(); $sel->select_window("null"); } $sel->click("emailAddress"); $sel->type("emailAddress", "anon@anywhere.com"); $sel->click("password"); $sel->type("password", "password"); $sel->click("remember"); $sel->click("subButton"); $sel->wait_for_page_to_load("60000");