Thursday, June 30, 2011

WebDriver querying Text Nodes - Lessons learnt

Earlier on today I ran into an odd problem while using WebDriver as part of my ongoing foray into Cucumber as a DSL. I was to trying write automated tests that verified that a link (a tag) had a text node. I could locate the link by an xpath locator.

I can hear you ask why this should be a problem. It was because the link looked as follows:


It turns out the usual WebDriver incantations along the lines of findElement(By.xpath("arbitrary-xpath")).getText() was returning nothing for the link's text. I looked around for a while and found that the only solution I had was to look things up via Javascript seeing as there were no ids to fallback on.

In the end it worked out that document.evaluate became the saviour of the day, since it allowed me to make xpath queries on a document. The result is a java step definition and cucumber feature file that look as follows:






UPDATE: Changed the step definition file so that the xpath lookup is done in WebDriver instead of in the javascript seeing as xpath lookups cannot be relied upon in Internet Explorer.

I suppose you could argue that the html could be changed to be better. True, but atimes that might not be an option. The purists will argue as they do here that it isn't a feature that should be provided by WebDriver but I think it would help to have a way of traversing the DOM once you have looked up an element. I should like to read about other creative solutions to a problem of this nature.

34 comments:

Anonymous said...

buy tramadol online tramadol 50 mg 4 times a day - tramadol apap 37.5 dosage

Anonymous said...

xanax online what is the lowest dose of xanax - drug interactions dramamine xanax

Anonymous said...

generic xanax withdrawal symptoms xanax use - xanax overdose wiki

Anonymous said...

buy tramadol online using tramadol withdrawal opiates - ultram vs tramadol generic

Anonymous said...

buy tramadol tramadol 50mg ndc - ultram side effects withdrawal

Anonymous said...

buy generic tramadol tramadol dosering - tramadol hcl 50 mg tablet r&s

Anonymous said...

buy cheap tramadol tramadol for dogs side effects - tramadol for dogs side effects panting

Anonymous said...

buy tramadol online how can i buy tramadol online - overdose symptoms for tramadol

Anonymous said...

xanax online best website to order xanax - buy xanax philippines

Anonymous said...

buy tramadol no prescription best place buy tramadol online reviews - can order tramadol online

Anonymous said...

buy carisoprodol buy carisoprodol cod - carisoprodol 350 mg listaflex

Anonymous said...

buy tramadol online tramadol 100 mg withdrawal - tramadol no prescription next day

Anonymous said...

where to buy cialis online no prescription generic cialis tadalafil - cialis recommended daily dose

Anonymous said...

buy cialis online can buy real cialis online - viagra or cialis online

Anonymous said...

cialis online cialis online usa pharmacy - cialis informacion en espanol

Anonymous said...

buy cialis online buy legit cialis online - generic cialis us online

Anonymous said...

buy xanax bars online xanax bars 15 - xanax side effects women

Anonymous said...

buy cialis online cialis tadalafil reviews - order cialis online prescription

Anonymous said...

xanax online generic xanax thailand - xanax + 1 mg per day

Anonymous said...

learn how to buy tramdadol buy tramadol order cheap tramadol online - tramadol dosage indications

Anonymous said...

learn how to buy tramdadol tramadol purchase online no prescription - tramadol for dogs 10 mg

Anonymous said...

buy tramadol tramadol vs hydrocodone dosage - buy cheap tramadol overnight

Anonymous said...

buy tramadol tramadol with acetaminophen high - tramadol withdrawal weight loss

Anonymous said...

buy tramadol online cheap tramadol withdrawal joint pain - best website buy tramadol

Anonymous said...

http://reidmoody.com/#92465 ativan vs xanax fear flying - lorazepam 1mg street value

Anonymous said...

buy tramadol online cyclobenzaprine and tramadol high - best buy tramadol

Anonymous said...

generic xanax overdose by xanax - xanax drug screen

Anonymous said...

order alprazolam xanax 93833 - xanax 0.5

Anonymous said...

Youг own artіcle has proνen helpful to
me personally. It’s verу infοrmative and you really are nаturally reаlly educatеd in this field.
You hаve gоt opened my personal еyеs for you to varying νiewѕ
on this speсific topіс with interesting
and sound wrіtten content.
Also visit my website :: meridia

Anonymous said...

Your own post hаs confirmed hеlpful to me pеrsonally.
It’s reаlly іnformative and you're certainly extremely well-informed in this field. You get popped my personal eye to be able to numerous thoughts about this kind of matter with intriquing, notable and sound articles.
Also visit my blog post ... Buy Valium

Anonymous said...

order topiramate online [url=http://www.topamaxrxonline.net/]Topamax For Sale[/url] generic topiramate

Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...

Gгeetingѕ from Carolіna!
I'm bored to tears at work so I decided to check out your website on my iphone during lunch break. I really like the info you present here and can't wait tο
takе a lοοk when I get home. I'm surprised at how quick your blog loaded on my mobile .. I'm not even
using WIFI, just 3G .. Anyways, amazing sitе!

Fеel free to νiѕit my wеb blog :: DiamondLinks.net

Anonymous said...

[url=http://my.moverapid.com/neggram][img]http://my.moverapid.com/promo.gif[/img][/url]





[size=4][url=http://my.moverapid.com/neggram][b][color=blue]Buy [/color][color=red]Neggram[/color][color=blue] ONLINE - click here![/color][/b][/url][/size]