Željko Filipin's Blog on Software and Testing

Test like you do not need the money.

Archive for May, 2007

Watir Has A New Method: after?

with 2 comments

Imagine that you have two links. Both links are the same.

<a>text</a>

The only thing that makes them different is that the second one is located after an image.

<a>text</a>
<img src="image.png" />
<a>text</a>

Of course, you just have to click the second link. You have already tried this.

browser.link(:text, "text").click

But, it always clicks the first link. There is a way.

browser.link(:after?, browser.image(:src, /image/)).click

This is so cool.

(You will need Watir 1.5. Bret Pettichord posted that at wtr-general.)

Written by Željko Filipin

May 25th, 2007 at 2:35 pm

Posted in Watir

Tagged with

New Watir User Guide (Beta)

without comments

Don’t you just love all those betas? There is another one! New Watir User Guide (Beta). Check it out and let me know what you think about it. It is just a first draft. Please, be polite. It is just a baby.

Written by Željko Filipin

May 18th, 2007 at 10:01 am

Posted in Watir

XPath String Functions

without comments

I have XML that looks like this.



I need to get value of hash attribute (BF8E8F60E722E92C7ED8303916591AB4). I know the value of m url parameter (inside url attribute) (7fb83717-9606-4022-bd4e-67b6f6582ada), but I do not know the value of code url parameter.

I know how to get attribute of a tag when I know another attribute of that tag. For example, if I knew hash attribute and needed url attribute, I would do it like this:

e = REXML::Document.new(ie.text).root.elements
e["/tokens/ShortUrl[@hash='BF8E8F60E722E92C7ED8303916591AB4']“].attributes["url"]
=> “resetpassword.aspx?m=7fb83717-9606-4022-bd4e-67b6f6582ada&code=2271ad0e-d627-4e6c-bdfb-2b11d354e9ac”

But, I know only part of url attribute. Of course, this does not work (because e[...] returns nil).

e["/tokens/ShortUrl[@url='resetpassword.aspx?m=7fb83717-9606-4022-bd4e-67b6f6582ada&code=']“].attributes["hash"]
=> NoMethodError: undefined method `attributes’ for nil:NilClass

I have heard that there are XPath string functions, but I did not understand how to use them, or would it even help in this case.

I have solved this problem with regular expressions, but I guess there must be XPath solution.

Also, I have already asked my developer to simplify that XML, so I can use it, but that has low priority because I have already solved the problem.

Angrez Singh was kind enough to help me. This is the solution.

e["/tokens/ShortUrl[starts-with(@url, 'resetpassword.aspx?m=7fb83717-9606-4022-bd4e-67b6f6582ada&code=')]“].attributes["hash"]
=> “BF8E8F60E722E92C7ED8303916591AB4″

You can find this thread at wtr-general.

Written by Željko Filipin

May 15th, 2007 at 11:03 am

Posted in Ruby