Željko Filipin's Blog on Software and Testing

Test like you do not need the money.

MatchData

with 2 comments

p6090020.jpg

Sapna asked how to extract id from this link.


RE: Check Copy Request

The solution includes using MatchData. I use it rarely, and I always forget how it is used. So, every time I need it, I have to read documentation. I have decided to make a note here, so I could easily find it later.

This is how you can get href attribute of that link. I will assumed that he knows text (“RE: Check Copy Request”).

ie.link(:text, “RE: Check Copy Request”).href
=> “MessageDetail.aspx?id=1303&messageToUser=True”

This will extract 1303.

m = /id=(1303)/.match(ie.link(:text, “RE: Check Copy Request”).href)
=> #

m[1]
=> “1303″

Written by Željko Filipin

June 11th, 2007 at 4:56 pm

Posted in Ruby

2 Responses to 'MatchData'

Subscribe to comments with RSS or TrackBack to 'MatchData'.

  1. Here is another way:

    (ie.link(:text, “RE: Check Copy Request”).href =~ /id=(.*)&/)[1]
    > “1303″

    bret

    12 Jun 07 at 7:22 am

  2. Thanks Bret. It is nice to know more than one way to do something.

    Željko Filipin

    12 Jun 07 at 9:44 am

Leave a Reply