Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^6: Using WWW::Selenium To Test Or Automate An Ajax Website

by Limbic~Region (Chancellor)
on Nov 27, 2009 at 18:16 UTC ( #809788=note: print w/ replies, xml ) Need Help??

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

Are you using the Selenium IDE FireFox plug-in to record your session and then modify it? Also, you are using Test::WWW::Selenium not WWW::Selenium. I think you want the latter not the former.

I am not sure how to help you. Your code sample is fairly useless without the real website so that I can try it here to see what you are doing wrong. I am sorry, but unless you want to share the website and possibly login credentials, I can't guess what you are doing wrong.

Update: As to your syntax errors - you should always use strict and use warnings. You have used else when you meant elsif. Also, you should either \ or you should use single quotes because it thinks your email address is really an array.

Cheers - L~R

Comment on Re^6: Using WWW::Selenium To Test Or Automate An Ajax Website
Re^7: Using WWW::Selenium To Test Or Automate An Ajax Website
by icleave (Initiate) on Nov 28, 2009 at 11:02 UTC


    Q: Are you using Selenium IDE FireFox plug-in to record?

    A: Yes. I have it record what I want to do, then I use the export function to put the Selenium commands into perl, then copy and paste into a text editor and remove the "_ok"s and place "sel->start();" in the code.

    RE: Test::WWW::Selenium - Thanks I changed that, but my code doesn't seem to run how I want it to.

    RE: Real website and login - The real website and my login is real in the code below.

    RE: Else, elsif, \@ - Thanks, I changed that too but my code doesn't seem to run how I want it to.

    Desired outcome:

    1. Go to
    2. Login (and handle any pops if they happen
    3. Check the number of points in the account and put into a scalar variable $points
    4. Open a file handle <CODES> and read the codes into an array @codes
    5. Enter the codes into the website and check against the $points scalar variable to see if they were entered correctly - printing if the code was successful or not
    6. Carry on for each of codes in the array @codes
    7. Logout when done

    Progress: I've only gotten as far as no. 2 in the Selenium IDE, and I can only get to no. 1 using the Selenium RC and Perl.

    I'm pretty confident I can write a file handle and read it into an array and for each of the codes get Selenium to input them into the CokeZone website, however it's no use if I can't even automate a login that handles the popups!

    Code I've written to try to login and handle the popups:

    #! /usr/bin/perl use strict; use warnings; use WWW::Selenium; my $sel = WWW::Selenium->new( host => "localhost", port => 4444, browser => "*chrome", browser_url => "http://www.cokezon" ); $sel->start(); $sel->open("/home/index.jsp"); $sel->click("link=Log in"); $sel->wait_for_page_to_load("30000"); if ( $sel->is_text_present("Thanks for visiting!\n\nNow here's your ch +ance to tell us what you think. This quick and easy survey will only +take you a few minutes to fill out, and it'll help us to get more of +the stuff you want to see into 'Coke Zone'.\n\nThanks for your help,\ +nThe 'Coke Zone' Team") == 1 ) { $sel->select_window("entry"); $sel->close(); $sel->select_window("null"); } if ( $sel->is_text_present("At the end of your visit on this website p +lease take the time to complete an on-line survey, which will provide + us with feedback on the website. Please do not close this window.\n\ +nEnjoy your visit") == 1 ) { $sel->select_window("stealth"); $sel->close(); $sel->select_window("null"); } $sel->click("emailAddress"); $sel->type("emailAddress", "bogus\"); $sel->type("password", "password"); $sel->click("remember"); $sel->click("subButton"); $sel->wait_for_page_to_load("30000"); my $points = $sel->get_text("//div[\@id='header_links']/div[1]/div[1]/ +h3"); print $points $sel->click("link=Log out"); exit 0;
      Please remove your user name and password. That is a stupendously bad idea. I assumed you would have /msg'd them to me. I have them now and will update this node later today with a working version.

      Update: It appears that codes appearing on US bottles of coke do not work at the UK site. I will need a few codes to make this work - you have my email address.

      Update 2: While I read the terms of use and didn't see anything preventing scraping or automation, the US site heavily relies on JavaScript that gives the appearance of thwarting this type of automation.

      • I needed to use $sel->focus($loc) to ensure the 'onFocus' event triggered
      • The above could also have been accomplished with $sel->fire($loc, 'event')
      • I also needed to use $sel->mouse_over($loc) before clicking the button
      Additionally, the site used fancy CSS to get you to click on an image of what kind of soda the code came from. After spending a lot of time getting that "just right", I realized it was not necessary - if entered the next code it would just silently update your points. You can also completely ignore any pop-ups when you go to the site because they do not interfere with site interaction.

      I would be happy to share with you the code I wrote to automate the US site but I don't know how applicable it will be to the UK site. Beyond that, I am not interested in doing this for you as it is very time consuming to get "just right". You have my email if you would like to consider other arrangements.

      Cheers - L~R

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://809788]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-10-02 12:12 GMT
Find Nodes?
    Voting Booth?

    What is your favourite meta-syntactic variable name?

    Results (56 votes), past polls