Forum Discussion

MichaelMcFarlan's avatar
MichaelMcFarlan
Contributor
14 years ago

Website requires a inspection from the object browser before code works

I am trying to get the state out of this this webpage: http://www.paycheckcity.com/calculator/netpay/us/arizona/calculator.html.

You'll notice that if you change the state at that page, the entire website URL will change. I am using IE9. This is the code I have come up with (in javascript):



function getOpenState() {

  lMatchStr = 'Page("http://www.paycheckcity.com/calculator/netpay/us/';

  lMatchLen = lMatchStr.length;



  lIE = Sys.Process("IEXPLORE", 2);

  lCount = lIE.ChildCount;

 

  for (var i = 0; i < lCount; i++) { // Look at all the children until we find the one that has the webpage we want

    lName = lIE.Child(i).Name;

    //Log.Message(lName);

    

    if (lName.substr(0, lMatchLen) == lMatchStr) { // found the IE page

      lRet = lName.substr(lMatchLen, lName.length - lMatchLen); // get everything past lMatchStr for further processing

      return lRet.substr(0, lRet.indexOf("/", 0)); // return everything before the /

    }   

  }

}



This works fine, but if you change the state this function is still getting the last state that the website was on. The only way I'm getting TestComplete to realize that the state has changed is if I use the object browser to inspect anything on the page.



Is there a better way to do this? Or this a bug in TestComplete? Or my code is incomplete somehow? I haven't done much web testing with TestComplete so any help would be appreciated. Also please let me know if my problem isn't clear.
  • amit_deshpande's avatar
    amit_deshpande
    Occasional Contributor
    Hi,



    I am not sure what state of the web page means specific to your application.



    If the state is changed after the code is executed as you have mentioned above , i would recommend to use either Sys.Refresh() or IIE.Refresh() in your case. This would refresh the child objects in the process tree and you will get the desired webpage after executing the code.



    Thanks and Regards,



    Amit 
  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi Michael,


    Amit is right. The code below returns the correct value of the State for withholding field.



    function getOpenState() {

      lMatchStr = 'Page("http://www.paycheckcity.com/calculator/netpay/us/';

      lMatchLen = lMatchStr.length;

      lIE = Sys.Process("IEXPLORE", 2);

      Sys.Refresh();

      lCount = lIE.ChildCount;

        for (var i = 0; i < lCount; i++) { // Look at all the children until we find the one that has the webpage we want

        lName = lIE.Child(i).Name;

        //Log.Message(lName);

       if (lName.substr(0, lMatchLen) == lMatchStr) { // found the IE page

          lRet = lName.substr(lMatchLen, lName.length - lMatchLen); // get everything past lMatchStr for further processing

          return lRet.substr(0, lRet.indexOf("/", 0)); // return everything before the /

        }  

      }

    }



    Did you try using it?