0

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>            
   <br>                                                                                            
   Our customer service team is available Monday to Friday,                                    
   <br>                                                                                            
   8AM - 12AM (Midnight) EDT, via phone, email or live chat.                                      
</p>

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

//p[@class='customer-service']/text()[2]

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 at 7:03
  • You cannot use text node as locator , see the attached answer – PDHide Jul 1 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 at 7:08
1

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

enter image description here

| improve this answer | |

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