Selenium IDE – How to follow links that open a new window

9

While building another test case, I ran into a situation that wasn’t working with the standard point and click navigation. Clicking on a dynamic link opened a new window where I needed to continue my test, but selenium didn’t follow the newly opened window. There are a few ways to do this, but what made this one difficult was that the link and new window was a dynamic url each time.
The fix was to store the link in a variable, then open the variable link with selenium using “open”. To store the variable I used “storeAttribute” and the target used xPath to grab the hyperlink’s href attribute from the url and save the variable as “ticketUrl” as in the image below:

Posted in: Selenium
Tags:

This article has 9 comments

  1. Kristin 11/17/2008, 6:11 pm:

    Thanks for this tip. This one has been driving me crazy all day. It’s not as good as testing that the link opens in a new window, but at least I can now write a test to check that it goes to the right url.

  2. Gavin Will 08/28/2009, 3:30 am:

    Thanks for this, I have just realised I have been downloading the same file after doing a MD5 check on them. The problem I had put in the absolute URL yet the filename / link changes with time. Hopefully this will resolve the issue.

    Many thanks

    G

  3. mats 01/20/2010, 4:16 am:

    Simple and functional. Excellent post. Thank you :)

  4. lakshmi kanta reddy 11/24/2010, 3:26 am:

    Hi,

    This is exactly, what i am looking for.
    Excellent topic, very much useful for selenium users
    thank u very much.

  5. abhiram sampath 02/04/2011, 3:06 am:

    Hey.. U have been a life -saver .. was looking for something like this !!!

    Thx a lot !!!!

  6. Shiro 03/02/2011, 7:15 am:

    Thank you very much for this post!

    I’ve been looking for a way to do this in Selenium this morning and was ready to give up thinking that it wasn’t possible until I found this post. :-)

  7. puja 04/06/2011, 7:53 am:

    while trying this i am getting error.
    # ] Executing: |storeAttribute | //a[@id=' http://ribadmin:ribadmin1@mspdev84.us.oracle.com:19102/rib-rms-admin-gui/index.jsp'@href | nwin |
    # [error] Element //a[@id=’ http://ribadmin:ribadmin1@mspdev84.us.oracle.com:19102/rib-rms-admin-gui/index.jsp' not found

    Please help me

  8. greg 01/05/2012, 12:51 pm:

    Now, the real kicker is how do you get to the new window that is lunched by clicking the submit button on a form where the button is simply

    and the forrm action

    and the page is simply the a online xml file
    returned from the soap api call

    3495

  9. greg 01/05/2012, 12:55 pm:

    whoops did not do the replaces before I hit return…

    Now, the real kicker is how do you get to the new window that is lunched by clicking the submit button on a form where the button is simply
    <input type=”submit” value=”Invoke” class=”button”>

    and the forrm action

    <form target=”_blank” action=”http://authservice.mysite.com/Accnt/Keys.asmx/Key.Create” method=”POST”>

    and the page is simply the a online xml file
    returned from the soap api call

    <int xmlns=”http://www.mysite.com/response”>3495</int>

Leave a Reply

Your email address will not be published. Required fields are marked *

*




You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">