Forum Discussion

dfontanesi's avatar
dfontanesi
Contributor
13 years ago

Find text on a page, even if it's in an iframe

I'm using the following code from the sample in the help:



Sub Test()

  ' Obtains the Page object and the document


  Set Pg = GetPage()

  Set Doc = GetDoc(Pg)

    

  ' Obtains the page's text


  bodyText = Doc.body.innerText

 

  ' Searches for the "Samuel Clemens" string in the page


  If InStr(bodyText, "Samuel Clemens") > 0 Then


    Log.Message("Found!")

  Else


    Log.Warning("Not found")

  End If


End Sub




But it won't match text that's contained in an iFrame.  How can I accomplish that?

5 Replies

  • Hi,



    Actually, TC has nothing to do with the innerText property contents. It is a native property of HTML objects retrieved from the browser. If it is empty or contain a value you don't expect to see there, this means that the object you're accessing holds this value internally.



    Try using child objects of your frame to obtain their text rather than using the frame itself.
  • Yeah, I was hoping for some sample code that accomplishes that.  I tried to write a recursive routine that appends together all the text in all the child frames but I couldn't get it to work.
  • Hi,



    To provide you with a sample script, we need to access your page. Otherwise, it is only possible to give you some general suggestions.



    As for the function you tried to create, it could help if you posted your code here and described the behavior you observe when you run it in detail.
  • If you could just tell me how to get the inner text of an iFrame I think I could figure out the rest.
  • Hi,



    To access inner text of an IFrame, you need to obtain it and address its innerText property. If it is empty, this means that the IFrame object itself doesn't contain any text, and you need to address the innerText property of its children.



    This depends on your page's behavior and on the way the IFrame object works on it. TC just shows you what it got from the browser, which gives TC what it got when parsing the page's HTML code.