Forum Discussion

chicks's avatar
chicks
Regular Contributor
13 years ago

accessing web page source?

My developers have added some javascript to every page on our website.  I can see the javaacript manually by selecting view web page source and seeing "script type ="text/javascript" src="<omitted>.js"</script> 



Is there some way to progammatically view the page source with test complete?  I do not see this in the outerrHTML of the page object.   



I suppose I could open up the page source graphically with testcomplete and then check the text contents but that seems very awkward.



Thanks.

7 Replies

  • In theory



    page.contentDocument.Script[scriptFunctionName]



    should return undefined if scriptFunctionName doesn't exist, so there's no need to loop through all the scripts.
  • Another way is the following call:

    page.QuerySelector("script[src='<omitted>.js']").outerHTML
  • chicks's avatar
    chicks
    Regular Contributor
    After some discussion with the developer, I need to access the "header tag" which so far I have not been able to spot with object spy.  I'm looking into object spy settings now....
  • Object Spy isn't going to help because the head is not a visible element.



    You can get the head tag's source programmatically with something like:



    Aliases.iexplore.Page("*").Application.Document.head.outerHTML
  • chicks's avatar
    chicks
    Regular Contributor
    Thanks very much Nick and Alexei!



    Nick,  I'm getting a javascript error outerHTML is null or not an object.  But when I back up the line  to Aliases.iexplore.Page("*").Application.Document    it's fine, but of course I don't see the source code. 



    Alexei,  I'm reviewing your link now.   I'm not all the way through but I don't want to execute the script just see if it's there.



  • chicks's avatar
    chicks
    Regular Contributor
    So, what I'm currrently doing is using the scripts collection from the document object for the entire page (not just the head tag) and then iterating through all  the scripts to determine if the script is there or not.



    (As opposed to getting the raw source and searching for the text.)   I'd still like to be able to get the raw source for a particular tag and am interested if anybody has a better method for isScriptOnPage...





    function isScriptOnPage(uniqueScriptTag) {

        page = currentPage();

          allScripts =   page.contentDocument.scripts;

          var found = false;   

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

              if (allScripts.src.indexOf(uniqueScriptTag) != -1 ) {

                   found = true;

                   break;

              }

          }

          return found;

    }