1
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">

                               
Ket
  • 55
  • 7
  • I am also trying //*[@id='page']/child::div//div//section//div/child::div/p This locates element perfectly but while running it says no such element – Ket May 05 '22 at 12:55
  • 1
    Is the p already there at first pageload? If not take a look at I.e. https://stackoverflow.com/a/11738528/3710053 – Siebe Jongebloed May 05 '22 at 13:00
  • Thank you for replaying but do you think my xpath is wrong and can get better? – Ket May 05 '22 at 13:02

1 Answers1

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']
Siebe Jongebloed
  • 3,906
  • 2
  • 14
  • 19
  • Thank you so much.. String error= wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='page']/child::div//div//section//div/child::div/p"))).getText(); helped me :) – Ket May 05 '22 at 13:19
  • child:: is not needed, but maybe for being explicit okay. So This XPath has the same outcome: `[@id='page']/div//div//section//div/div/p` – Siebe Jongebloed May 05 '22 at 13:21