Reputation: 213
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
Reputation: 115
Try This
//div[1][starts-with(@class,'email')and contains(.,'.com')]
Upvotes: 0
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
Reputation: 1388
Please try this
//div[@class='email' and contains(.,'.com')][1]
Upvotes: 1