Forum Discussion

dale_waterworth's avatar
dale_waterworth
Occasional Contributor
12 years ago

Handling the adobe popup for string found or not

Hi



Please see image...



I'm searching through the contents of a pdf using Adobe Reader using the ctrl + f.



My check is if the string does not exist, then check for the dialog to appear and and click ok. if it is found then the box does not appear, which is fine and this denotes a find.



My main pdf window uses (jscript):



Sys.Process("AcroRd32", 2).Window("AcrobatSDIWindow", "*", 1)



the confirm box is:

Sys.Process("AcroRd32", 2).Window("#32770", "Adobe Reader", 1).Window("GroupBox", "", 1)



How can do the error check without it breaking? I've tried various conditions in the if statement such as waitProcess etc but cant find the correct one to use.



Code - this works fine when the text isn't found but when the dialog doesn't appear it breaks and i get an error:



Cannot obtain the window with the window class '#32770', window caption 'Adobe Reader' and index 1. See Additional Information for details. 16:31:22 Normal :



To run you should be able to open a pdf in adobe and run this keyword function against it. change the 'find' variable to contain words in the pdf doc and then the problem will occur






function findtText() {

  var find = "imNotHere, the, a"


  var findList = find.split(",");


  var i =0;


  var notFound = false;


  var notFoundStr = "";


  var adobe = Sys.Process("AcroRd32", 2).Window("AcrobatSDIWindow", "*", 1);


  var val;


  for(i = 0; i < findList.length; i++) {


    val = aqString.Trim(findList);


    adobe.Keys("^f[BS]");


    adobe.Keys("^f" + val + "[Enter]");


    aqUtils.Delay(750);


    


    if(Sys.Process("AcroRd32", 2).Window("#32770", "Adobe Reader", 1).Window("GroupBox", "", 1).Exists) {


      Sys.Process("AcroRd32", 2).Window("#32770", "Adobe Reader", 1).Window("GroupBox", "", 1).Window("Button", "OK", 2).Click();


      notFoundStr += "[" +val + "]";


      notFound = true;


    } else {


      Log.Checkpoint("Found: [" + val + "]");


    }


  }


  


  if(notFound) {


    Log.Error("Could not find [" + notFoundStr + "] in pdf");


  }  


}



Cheers



2 Replies

  • marin's avatar
    marin
    Frequent Contributor
    Hello Dezza,



    I have a similar scenario in one of my test cases.

    The approach I am using is to capture entire contents of the PDF document into clipboard and then search for the string in question:







      //Capturing entire contents of PDF document from Adobe Reader popup into clipboard (CTRL + A, CTRL + S)

      //and converting the variant into string, then searching the content for desired substring

     Aliases.AcroRd32.wndAcrobatSDIWindow.AVSplitterView.AVSplitterView.AVSplitationPageView.AVSplitterView.AVScrolledPageView.AVScrollView.AVPageView.Keys("^a^c");

     

      var clip = aqConvert.VarToStr(Sys.Clipboard);

      var chkRefNo = aqString.Find(clip, "ABC_123");

     

      //searching for "ABC_123"  in clipboard

      if (chkRefNo < 0)

      {

        Log.Error("Reference number ABC_123 is not displayed on PDF.")

      }

      else

      {

        Log.Checkpoint("Reference number ABC_123 is displayed on PDF.")

      }







    Hope this helps.



    Regards,



    Marin
  • dale_waterworth's avatar
    dale_waterworth
    Occasional Contributor
    Hi Martin



    Good thinking - makes sense. I already use this technique elsewhere but never thought of it.



    Cheers.