'How do I get to P tag in the below HTML using Xpath ? Thanks

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" class="same-as-sidebar ng-scope" ng-class="{
>             'hide-mainnav' : (Engine.hideMainNav == true),
>             'not-loaded': (!Engine.readyAnimate == true)
>             }" ui-view="content" style="">
>                         <div class="main ng-scope">
>                             <!-- uiView: content --><section ui-view="content" class="ng-scope">
>                         <div class="main ng-scope">
>                             <!-- uiView: content --><section ui-view="content" class="ng-scope">
>                                 <div class="row ng-scope">
>                                     <div class="col-md-12">
>                                         <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 class="row">

                               


Solution 1:[1]

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']

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Siebe Jongebloed