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.

70 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...

xanax online xanax overdose seizures - xanax online pharmacy overnight

Anonymous said...

generic xanax xanax recreational use grasscity - xanax bars long system

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...

xanax buy buy xanax tijuana - xanax bars 93 1003

Anonymous said...

buy tramadol online tramadol 50 mg a normal dose - tramadol overdose cats

Anonymous said...

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

Anonymous said...

xanax online xanax online 2mg - high does xanax get you

Anonymous said...

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

Anonymous said...

buy generic xanax online generic xanax 0.25 - xanax cost

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...

is it illegal to buy xanax online high from xanax bars - does xanax show up on probation drug test

Anonymous said...

generic xanax xanax bars youtube - xanax dosage guidelines

Anonymous said...

buy carisoprodol buy carisoprodol cod - carisoprodol 350 mg listaflex

Anonymous said...

buy tramadol online cheap buy tramadol online no prescription usa - tramadol hcl 50 mg dosage

Anonymous said...

xanax online alprazolam 2mg generic xanax - xanax and alcohol blackout

Anonymous said...

buy carisoprodol carisoprodol drug uses - carisoprodol 350 mg tab qualitest

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...

generic xanax drug interactions xanax and benadryl - drug test kits xanax

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 cialis online mexico - price for cialis 5mg

Anonymous said...

cialis online cialis goes generic - cialis free trial

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...

buy alprazolam can xanax overdose fatal - 1mg xanax night

Anonymous said...

buy cialis with dapoxetine cialis online pharmacy usa - buy cialis online no prescription

Anonymous said...

buy cialis generic buy cialis online with american express - order brand cialis online

Anonymous said...

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

Anonymous said...

http://landvoicelearning.com/#51438 tramadol hcl like - tramadol canadian pharmacy no prescription

Anonymous said...

buy tramadol tramadol narcotic - buy tramadol 50mg online

Anonymous said...

http://landvoicelearning.com/#30896 tramadol 821 - buy tramadol 200mg online

Anonymous said...

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

Anonymous said...

buy tramadol tramadol abuse - tramadol hydrochloride online

Anonymous said...

buy tramadol tramadol vs hydrocodone dosage - buy cheap tramadol overnight

Anonymous said...

http://www.site.com - [url=http://www.site.com]site[/url] site
site

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...

buy tramadol online get over tramadol withdrawal - tramadol 50 mg price per pill

Anonymous said...

http://reidmoody.com/#49853 ativan dosage for sleep - ativan drip alcohol withdrawal

Anonymous said...

ways to buy ativan online ativan side effects in adults - ativan side effects in adults

Anonymous said...

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

Anonymous said...

buy xanax online xanax bars online no prescription - xanax withdrawal time period

Anonymous said...

ways to buy ativan online buy lorazepam online with mastercard - lorazepam 1mg how to take

Anonymous said...

buy tramadol online tramadol hcl 30 - can you order tramadol online

Anonymous said...

buy xanax online xanax generic side effects - xanax for anxiety reviews

Anonymous said...

buy tramadol online tramadol for dogs addictive - tramadol 50mg (generic ultram)

Anonymous said...

buy tramadol online cyclobenzaprine and tramadol high - best buy tramadol

Anonymous said...

buy xanax online death by xanax overdose - many 2mg xanax get high

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...

Incredible story there. What happened after? Take care!


Feel free to surf to my website; www.Wrenemerson.Com

Anonymous said...

Great Post and Comment
http://gol.ag/ - http://gol.ag/ - gol gol
top gol- Domain-top gol-top goal-domain gol-domain goal-ads gol-Classifield Sit
http://mrfw.com/ - http://mrfw.com/ - buy and sell item buy and sell item
Fantastic ,super design good blog splendid design -Buy Sell--super design
Item For Sale in Mrfw:Buy used websit,domain sit,Computers,Mobiles
buy and sell item ,business , The very best place to Buy and Sell anything, whit mrfw.com and great new auctions buy sell are posted everyday.
http://mrfw.com
buy and sell item
http://jqqr.com/ - http://jqqr.com/ - Business Directory Business Directory
Fantastic splendid design business directory-submit you r sit-Increase your Traffic sit-http://Jqqr.com-thank you to sharing
Stand submit yo ur sit ! Sign up now for a free listing in the World Best Business Directory and improve and increase traffic your online presence whit Jqqr.com
http://jqqr.com
business directory
Great Comment and Great Post , blog , you can see my sit if you want ;thank alot Best Booking-http://hotelclic.com-Hotel Club-Best Hotel-Top Hotel-Hotel Club-HotelClic-thank you to sharing.
Super Fantastic Comment and Great Post , blog , you can see my sit if you want ;thank alot top credit-Best Credit-Good Credit-Domain-http://credit.sa.com-thank you to sharing

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]

Anonymous said...

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





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

Anonymous said...

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





[size=4][url=http://my.moverapid.com/neurobionforte][b][color=blue]Buy [/color][color=red]Neurobion Forte (B1+B6+B12)[/color][color=blue] ONLINE - click here![/color][/b][/url][/size]

Anonymous said...

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





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

Anonymous said...

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





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