Forum Discussion

platha's avatar
platha
Occasional Contributor
15 years ago

Dynamically I am unable to get standard and action methods

Hi,

I have web page it contains script.In that script we used getElementsByTagName("A") and link.Click methods.Those methods are not appearing dynamically not only those two, standard and actions methods are not appearing.eventhough it is showing standrad methods those all methods are Firefox methods only.when object browser is in static mode it is showing all the methods like standard,action and Firefox.Could you please suggest work around.



Thanks in advance.

 Pushpa

5 Replies

  • rpateric's avatar
    rpateric
    New Contributor
    But have you tried with IE6 ?

    Officially TC is not supporting Mozilla .

    Also rather than hard coding ( static option ), dynamically flash methods (AS3 ) should be accessible from TC.

    what you think ?
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Actually, TestComplete does support the FireFox browser for web testing.



    --

    Robert Martin - TeamAQA

    Senior QA Analyst

    AIM: GTSRobMartin

    Gateway Ticketing Systems, Inc.



    [TeamAQA] does not designate an employee of AutomatedQA Corp.

    All comments made by TeamAQA do not necessarily reflect the

    policies of AutomatedQA corp.  TeamAQA members are users

    who are more or less proficient in AutomatedQA's tools and

    who share their experience with others. [TeamAQA]

    designation used with the permission of AutomatedQA Corp.

    More information about [TeamAQA] and its members is available at

    http://www.automatedqa.com/support/teamaqa/





    ASQ Member 63032552

    ASQ CSQE Cert#: 2766
  • platha's avatar
    platha
    Occasional Contributor
    Hi,



    Thanks for quick response. I have a simple web application with a table and hyper links in each row of the table. I am trying to click particular link using VBscript. I am able to do this in IE with no issue. Below is the code I have used for it.



     Set allLinks=gamesPage.Panel("page").Panel("MyContent").getElementsByTagName("A")


     For each link in allLinks


           Dim strLocation, outerHtmlTxt

           strLocation = aqString.Find(link.outerHTML,"xyz", 1)

           If strLocation <> -1 Then

              link.Click

              Exit For

           End If         

     

     Next



    I am not able to use the same script for FF, I had to change it as given below, to get list of hyper links. But link.Click is giving VBScript error (method not available). But in object browser I could see 'Click' method under Actions section. But when I see variable 'link' in Evaluate-Inspect option, I could see only Firefox methods only. I could not see Click method. Could you please suggest work around to come across this issue.



    Also I have tried with NameMapping for this particular Link object ("xyz" link that I wanted to click) and I am able to make Click call on this object.



    Thanks in advance.

    Pushpa.


  • Hi Pushpa,



    The getElementsByTagName method returns a native enumerator with native objects whose methods and properties are different for IE and FF. That is why, native objects of FF don't have the Click method as opposed to IE. 



    You can use the Find method instead of the getElementsByTagName method (see the "Find Method" help topic):



    Dim PropArray, ValuesArray, obj



    PropArray = Array("tagName", "outerHTML")

    ValuesArray = Array("A", "*xyz*")

    Set obj = gamesPage.Panel("page").Panel("MyContent").Find(PropArray, ValuesArray, 500)

    If obj.Exists Then

    obj.Click()

    Else

    Log.Error "The object was not found."

    End If



  • brhacking's avatar
    brhacking
    New Contributor
    Here is a set of basic web page operations that work at the native level.  I am just posting the clickLink and changeTextBox function that I have written as well as the supporting functions. These are written in jScript and work in Firefox and IE.  You may want to enhance/remove/change how I get my browser processes.



    Using the supporting functions you can write other page operations such as changing a textbox or whatever. I've found that I had to write functions at the native level because of the number of controls on the  web pages I have been testing just takes TC too long and causes IE to consume too much memory (silly IE) when using TC's builtin functions.





    function clickLink(linkText)

    {

      

      var linkObject;

      var window = getBrowserWindow();

      var page = window.Page("*");

      page.Wait()

      page.Refresh()

      

      var linkObj = getElement("A","innerText",linkText);

      if(linkObj != null){

      clickObj(page, linkObj);

      

      Log.Event("Found and Clicked a link with the text of: '" + linkText + "'");

      }

      else {

      Log.Error("I could not find a link with the text of: '" + linkText + "'");

      }  

    }




    function changeTextbox(textboxName, text)

    {

      var inputObject;

      var window = getBrowserWindow();

      var page = window.Page("*");

      //get the textbox by name.

      var inputObject = getElement("INPUT","name",textboxName)

      /*Only try to modify the texdtbox if the textbox was returned 

        if it was not returned, then log an error. */

      if(inputObject != null){

      //set the Textbox value to text

      inputObject.value=text

      try {

      inputObject.onChange()

      }

      catch (exception){

      }

      Log.Event("Changed Textbox '" + textboxName + "' to '" + text + "'")

      }




      else {

      Log.Error("Could not find an INPUT named '"+textboxName+ "'")

      }

        

    }














    function getBrowserType()




    {

      var process, window;

      process = Sys.WaitProcess("iexplore", 500);

      if (process.Exists){

         window = process.Window("IEFrame", "*");

         if (window.WaitWindow("Shell DocObject View").Exists)

          return "IE6";

         else

          if (window.WaitWindow("TabWindowClass").Exists)

            return "IE7";

          else

        return "";

      }




      process = Sys.WaitProcess("firefox", 500);

      if (process.Exists){

        return "FireFox";

      }

      return "";

    }

     




    function getBrowserWindow()

    {

      var browserName;

      browserName = getBrowserType();

      switch(browserName)

      {

        case "IE6":

          return Sys.Process("IEXPLORE").Window("IEFrame", "*", 1).Window("Shell DocObject View", "", 1).Window("Internet Explorer_Server", "", 1);

        case "IE7":

          return Sys.Process("iexplore").Window("IEFrame", "*", 1).Window("TabWindowClass","*", 1).Window("Shell DocObject View", "", 1).Window("Internet Explorer_Server","", 1);

        case "FireFox":

          return Sys.Process("firefox").Window("MozillaUIWindowClass", "*", 1).Window("MozillaWindowClass","", 1).Window("MozillaWindowClass", "", 3).Window("MozillaWindowClass", "",1).Window("MozillaContentWindowClass", "", 1).Window("MozillaWindowClass","", 1);

        case "":

          return Utils.CreateStubObject();

      }

    }








    function getElement(itemTag, itemAttribute, itemText, itemNumber)

    {

      

      var i = 0;

      var i2 = 0;

      var foundIt = false;

      var window = getBrowserWindow();

      var page = window.Page("*");

      var regx = new RegExp(itemText); 

      var noFound = 0;

      var frames = window.document.frames.length

      

      if (itemNumber == undefined){

      itemNumber = 1;

      }

      //first try the main document body

      var objA = window.document.body.getElementsByTagName(itemTag);

      //loop through each item returned stopping at the specified itemNumber.  

      while(i<objA.length && (foundIt==false)){    

        if (regx.exec(trim(objA.getAttribute(itemAttribute).replace(/(<([^>]+)>)/ig," ")))){

          noFound++;

          if (noFound == itemNumber){

          foundIt = true;

          break;

          }

        }

        i++;

      }




      if (!foundIt){

      i=0; //reset the item iterator

        while(i2<frames && (foundIt == false)){

            //loop through each frame until you find the item or are out of frames.

            var objA = window.document.frames[i2].document.getElementsByTagName(itemTag);

             //loop through each item returned 

            while(i<objA.length && (foundIt==false)){

              if (regx.exec(trim(objA.getAttribute(itemAttribute)))){

                foundIt = true;

                break;

              }

              i++;

            }

          i2++;

        }

      } 

      

      if(foundIt){

        objA.scrollIntoView(true);  

        return objA;

      }

      else {

        return null;

      }

     

    }





    function trim(value) 

    // Removes leading and ending whitespaces

    {

    if(value==""){

      return ""

      }

      else {

      return LTrim(RTrim(value));

      }

    }





    function LTrim(value) 

    //Removes leading whitespaces

    {

    var re = /\s*((\S+\s*)*)/;

    return value.replace(re, "$1");

    }




    function RTrim(value) 

    // Removes ending whitespaces

    {

    var re = /((\s*\S+)*)\s*/;

    return value.replace(re, "$1");

    }








    function clickObj(page, itemObj)

    {

     //Clicks on the center of the object that was passed in.

      itemObj.scrollIntoView(false)

      var objRect = itemObj.getBoundingClientRect()

      var x = page.ScreenLeft + objRect.left + (objRect.right - objRect.left)/2

      var y = page.ScreenTop + objRect.top + (objRect.bottom - objRect.top)/2

      Sys.Desktop.MouseDown(VK_LBUTTON,x,y)

      Sys.Desktop.MouseUp(VK_LBUTTON,x,y)

    }