How to write an XPath query to match two attributes?

shola picture shola · Jan 5, 2010 · Viewed 160.3k times · Source

Following Question:

<div id="id-74385" class="guest clearfix" style="z-index: 999;">

Given above,

If I want a XPath expression with checks both id and class, can we do it w/ 'and' condition LIKE:

//div[@id='id-74385'] and div[@class='guest clearfix']

Is this correct way? My execution fails here... Please help!

Answer

Brian Agnew picture Brian Agnew · Jan 5, 2010
//div[@id='..' and @class='...]

should do the trick. That's selecting the div operators that have both attributes of the required value.

It's worth using one of the online XPath testbeds to try stuff out.