sharan
sharan

Reputation: 213

How to get xpath for this tag?

I am trying to select first element with valid Email id from these tags .

 <div class="email">[email protected]</div>
 <div class="email">adsdasdsa</div>
 <div class="email">[email protected]</div>

Currently am using this xpath: //div[@class='email' and contains(text()='.com')] . But I could not select the element. Please help me.

Upvotes: 0

Views: 102

Answers (3)

Raghuveer
Raghuveer

Reputation: 115

Try This

//div[1][starts-with(@class,'email')and contains(.,'.com')]

Upvotes: 0

olyv
olyv

Reputation: 3817

Your xpath should be //div[@class='email' and contains(text(),'.com')]. It will get first occurrence of this xpath. If you need exactly first or third element add [1] or [3] which specifies number of occurrence.

Upvotes: 0

nitin chawda
nitin chawda

Reputation: 1388

Please try this

//div[@class='email' and contains(.,'.com')][1]

Upvotes: 1

Related Questions