Take the 2-minute tour ×

I got html looking like this

<div id="depositModalxx" class="modal hide">
    <div class="modal-header">
        <h3> Deposit </h3>
    <div class="modal-body">
        bla bla bla

And in this file there is more than 1 modal, so i need to find it by text. I tried this

ancestor::div[.//div/h3/text() = 'Deposit']

But this returns more than just that div i am searching. Any ideas how to get just that div i want?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

This should work

//div[div/h3 = ' Deposit ']

If you also want to check that the div has the modal class you can do

//div[contains(@class, 'modal')][div/h3 = ' Deposit ']

I don't quite get why you don't simply search using the @id. As an id should be unique in the HTML anyways, you should also be able to select the element easily and realiably.

share|improve this answer
This is for selenium tests and @id is generating randomly by Wicket framework –  IowA Jul 15 '13 at 8:18

Your Answer


