سؤال

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

 <div class="email">adsdasdsa@gmail.com</div>
 <div class="email">adsdasdsa</div>
 <div class="email">asdsa@gmail.com</div>

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

هل كانت مفيدة؟

المحلول

Please try this

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

نصائح أخرى

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.

Try This

//div[1][starts-with(@class,'email')and contains(.,'.com')]
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top