I am working on a project and building automation test suite for a webpage. A certain part of the webpage looks like this.

Webpage element

The corresponding HTML is as follows:

<p class="customer-service">                                                                    
   <b>Try us out for 14 days. If you aren't satisfied, we'll refund your money.</b>            
   Our customer service team is available Monday to Friday,                                    
   8AM - 12AM (Midnight) EDT, via phone, email or live chat.                                      

I want to write an XPath for just the text "Our customer service team is available Monday to Friday,". In particular, I want to verify the text in my automation suite of the corresponding line. Is there any way to write an xpath using contains() or text()?

P.S. I tried the following xpath


and this was the result.

My XPath result

  • What about increasing the checkability of your page by adding a div around the phrase you want to fetch, so you can target it without any work-around solution like normalize-space? – João Farias Jul 1 '20 at 7:03
  • You cannot use text node as locator , see the attached answer – PDHide Jul 1 '20 at 7:07
  • you can use the suggested answer or just get the all text split it using line break (\n) and then get the second item in the list – PDHide Jul 1 '20 at 7:08

This will help you //p[@class='customer-service']/text()[normalize-space()][1]

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.