Home > Software design >  How do I get to P tag in the below HTML using Xpath ? Thanks
How do I get to P tag in the below HTML using Xpath ? Thanks

Time:05-06

I want to assert **"sorry you cant Sorry, you do not have access the to the requested page** but I am not able to reach there..  

I could get till here: //*[@id="page"]/child::div/following-sibling::section/

How do I proceed further? Below is my code:

> <section id="page"  ng- ui-view="content" style="">
>                         <div >
>                             <!-- uiView: content --><section ui-view="content" >
>                         <div >
>                             <!-- uiView: content --><section ui-view="content" >
>                                 <div >
>                                     <div >
>                                         <h1 style="
>                                             font-weight:bold;
>                                             font-size:0px;
>                                             width:100%;
>                                             text-align:center;
>                                             color:black;
>                                         ">
>                                             404 &nbsp;
>                                         </h1>
>                                         <img style="max-width:400px;margin:20px auto;display:block;" alt="404"
> src="/1124px-NL_Route_404.svg.png">
>         
>                                         <p style="margin:20px auto;width:100%;display:block;text-align:center;">Sorry, you do not
> have access the to the requested page</p>
>                                         <div >

                               

CodePudding user response:

It is alway good to look for elements with a @id-attribute. They should be unique and the XPath engine will probably find those the fastest. So that is oaky.

Since I assume that the order and number of divs vary and the presented sections don't seem to close in this example, I would use this XPath:

//*[@id="page"]//p[text()='Sorry, you do not have access the to the requested page']
  • Related