venkatesan_G02 has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

I am currently working with WWW::Selenium module and i am stuck up with the following problem.

My requirement is i need to search whether a particular window is open or not before performing any action.

I have given below a sample code i have been working with


#!C:/Perl/bin/perl.exe use WWW::Selenium; my $sel = WWW::Selenium->new( host => "localhost", port => 5555, browser => "*firefox", browser_url => "http://www.google. +com" ); $sel->start; $sel->open("/"); $sel->select_window("CPAN - Google Search"); $sel->pause("3000"); $sel->type("q", "www::selenium"); $sel->key_press("q","\\13"); $sel->pause("300"); $sel->stop;

This code searches if a window with title "CPAN - Google search" is open or not. If open, it will search for www::selenium in that google window. The window is open but still i am receiving Error: Could not find window with title CPAN - Google Search

Could someone help me out with this requirement?

Thanks

Replies are listed 'Best First'.
Re: Searching for a window using www::selenium
by Old_Gray_Bear (Bishop) on Feb 03, 2010 at 03:22 UTC
    If I read the documentation for WWW::Selenium correctly, $sel->select_window() needs additional help to determine the appropriate window:

    <quote>

    $sel->select_window($window_id) Selects a popup window using a window locator; once a popup window + has been selected, all commands go to that window. To select the mai +n window again, use null as the target. Window locators provide diffe +rent ways of specifying the window object:by title, by internal JavaS +cript "name," or by JavaScript variable. * title=My Special Window:Finds the window using the text that + appears in the title bar. Be careful;two windows can share the same +title. If that happens, this locator willjust pick one. * name=myWindow:Finds the window using its internal JavaScript + "name" property. This is the second parameter "windowName" passed to + the JavaScript method window.open(url, windowName, windowFeatures, r +eplaceFlag)(which Selenium intercepts). * var=variableName:Some pop-up windows are unnamed (anonymous) +, but are associated with a JavaScript variable name in the current a +pplication window, e.g. "window.foo = window.open(url);". In those ca +ses, you can open the window using"var=foo". If no window locator prefix is provided, we'll try to guess what y +ou mean like this: 1.) if windowID is null, (or the string "null") then it is assumed + the user is referring to the original window instantiated by the bro +wser). 2.) if the value of the "windowID" parameter is a JavaScript varia +ble name in the current application window, then it is assumed that t +his variable contains the return value from a call to the JavaScript +window.open() method. 3.) Otherwise, selenium looks in a hash it maintains that maps str +ing names to window "names". 4.) If that fails, we'll try looping over all of the known windows + to try to find the appropriate "title".Since "title" is not necessar +ily unique, this may have unexpected behavior. If you're having trouble figuring out the name of a window that yo +u want to manipulate, look at the Selenium log messages which identif +y the names of windows created via window.open (and therefore interce +pted by Selenium). You will see messages like the following for each + window as it is opened: debug: window.open call intercepted; window ID (which you can use with + selectWindow()) is "myNewWindow"
    </quote>

    I suspect that you are falling into items 3 and 4, and the name of the window isn't really "CPAN - Google Search". (In my browser, the window is titled "CPAN - Google Search - Mozilla Firefox".)

    Update -- Cleaned up the syntax in the first sentence.

    ----
    I Go Back to Sleep, Now.

    OGB

      Hi,

      Is there a way to find the ID of the open window. Please note that the window is not opened by window.open command.
        venkatesan_G02,
        Have you read Using WWW::Selenium To Test Or Automate An Ajax Website? In there, I showed an example of how to find a window not opened with window.open. It might not be immediately useful but if you combine it with some of the other Selenium methods (get_all_window_ids or get_all_window_titles), you should be able to figure it out.

        Cheers - L~R