Forum Discussion

Brentp's avatar
Brentp
Occasional Contributor
9 years ago
Solved

Permission Denied - when attempting to use Exists.

I'm running in to an intermittent problem (10% of the time) where myControl.Exists is giving me a Microsoft JScript runtime error.  I run in to in several places in my code, but one such example is where I'm attempting to wait for a control to become available, and when it does I click on it.  Here is the code that is generating the problem.  

 do { myControl = page.FindChildByXPath(xpath_element); }

  while (!myControl.Exists && elapsedTime <= maxWait);

 

So far I've checked to ensure it's not related to my browser (since it happens in any browser), or my security level since I'm an admin on my machine and all the files I'm working with are local.

 

I have a hypothesis on the cause, but it's just a stab in the dark.  These seem to correlate to when the page is going out to the database to obtain updated records, then it updates the page.  Could it be related to the fact that the DOM is changing while this method is running?  PS I find the same problem when posting messages to the Log- also happens intermittently.  

 

I'd appreciate any thoughts on how to deal with this. 

 

Thanks!


Brent

4 Replies

  • Hi Brentp,

     

    Easy as pie :) 

    According to this article http://support.smartbear.com/viewarticle/55745/, the method FindChildByXPath return Null in JScript when the element is not found. So, you should make sure the page is fully loaded before using this method.

    What is happening in your case is that sometimes (when the error occurs), the application's response time is a little bit higher than when everything run smoothly.

     

    Best regards,

     

    Leandro de Araújo Souza

     

     

    • Brentp's avatar
      Brentp
      Occasional Contributor

      I've tried using .Wait and .WaitPage, but it's not working because the page is actually there already.

       

      Here is the timeline of the page as I understand it.

       

      1- Page is available prior to any updates

      2- I initiate the command which goes out to the DB to obtain the updated information.  The page is still "there", just not updated because the DB is retrieving the information and the update hasn't started yet. During this stage .Wait finds the page because it's already there, just not fully updated.  Since it finds the page, the next command in my script executes and crashes.

      3-the page is loading/updating the HTML.  During this stage I suspect that .Wait would work.  

      4- the page is fully loaded and updated again.

       

      I think the error occurs when I am trying to access the page between stage 3 and stage 4.  

       

      If I use the .Wait by initiating it at the end of stage 2 it 'finds' the not updated page in stages 2/3 rather than waiting until stage 4 is done. I'm not seeing a way to initiate the .Wait later than stage 2 without some hacky aqUtils.Delay.   

       

      thanks,

      Brent