Windows Server TechCenter > Windows Server Forums > Windows PowerShell > Cannot navigate frame's innerHTML because it shows as empty.
Ask a questionAsk a question
 

AnswerCannot navigate frame's innerHTML because it shows as empty.

  • Thursday, October 29, 2009 6:23 PMdave_i_h Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    I'm trying to setup some IE automation.  Currently I'm trying to access an anchor that is within a frame of the page.  I cann access the frame element but, when I view its innerHTML it is empty and the hasChildNodes method returns false.  Using the IE Developer toolbar add-on for IE I can see the DOM, the inner HTML of the frames and the anchor I want to navigate to but I'm unable to navigate via PS.  Following is example of HTML I'm trying to traverse:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML Transitional//EN"><META http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <HTML>
    <FRAMESET oncontextmenu="return false;" id="DESKTOPWRAPPERID" name="DESKTOPWRAPPERMAIN" frameSpacing="0" rows="46, *" frameBorder="0">
    <FRAMESET oncontextmenu="return false;" id="DESKTOPMAINID" name="DESKTOPMAIN" frameSpacing="2" frameBorder="0" cols="220px, *"> 
    <FRAME id="leftFrameId" title="Navigation Frame" onfocus="top.gFocus=false;" name="leftFrame" frameSpacing="2" src="/skle/HIMXXOServlet/ZdooMdJuMJqo-n2nxlqpNNg-aRt-toN_*/!STANDARD?Stream=NavigationPane&PrimaryPageName=Portal" frameBorder="0" scrolling="no" /> 
    </FRAMESET>
    </FRAMESET>
    </HTML>
    
    Here is my PS script:

    PS>$ie = new-object -com "InternetExplorer.Application"
    PS>$ie.navigate(<site url goes here>)
    PS>$ie.visible = $true
    
    ...wait for page to load...
    
    PS>$ie.document.getElementById("leftFrameId").name
    PS>leftFrame
    
    ...So I'm able to access the frame element...
    
    PS>$ie.document.getElementById("leftFrameId").innerhtml
    PS>
    
    ...Nothing is returned for innerHTML property...
    
    PS>$ie.document.getElementById("leftFrameId").hasChildNodes()
    PS>false
    
    ...No child nodes, however, viewing DOM via IE Developr Toolbar Add-on shows child nodes...
    Any suggestions would be appreciated.  Thanks.

Answers

  • Friday, November 06, 2009 3:24 AMMervyn ZhangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

    It’s more of a Web development issue, it’s suggested to submit a new post in the MSDN forum to get more suggestions. They are the best resource for this kind of problem.

    MSDN Forum
    http://forums.microsoft.com/MSDN/default.aspx?SiteID=1

    Thanks.

    This posting is provided "AS IS" with no warranties, and confers no rights.

All Replies

  • Thursday, October 29, 2009 8:23 PMMarco ShawMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
  • Friday, October 30, 2009 10:20 PMdave_i_h Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks for they reply.  Helpful suggestions but they did not resolve the problem.  I did some more research and found a proposed solution that states that I must navigate to the url of the frame in order to traverse it.  I did this using the IHTMLDocument4::createDocumentFromUrl method and I was able to traverse the frame's dom, however, when I try to invoke the click method on my anchor control nothing happens.  Is that the best method to use or is there a better way to navigate the frame's url(src)?
  • Friday, October 30, 2009 11:58 PMMarco ShawMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I'll admit to not completely following what you're doing...

    Now you mention trying to invoke a click method...  Is that a click method or click event?  Events aren't supported in PowerShell v1.  Out-of-the-box at least...  If you're using v1, I don't know how you'd (assuming it is possible) leverage: http://www.codeplex.com/pseventing .
  • Tuesday, November 03, 2009 3:46 PMdave_i_h Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    The click method; not the event.  As an example, I'm trying to do the following:

    PS>$btn = $ie.document.getElementById("elementid")
    PS>$btn.click()

    The problem is that the html control with the ID 'elementid' (an anchor tag in my situation) is in a series of nested frames.  I can access the frame where the anchor control resides but, the frame shows as having no child nodes.  It has been suggested that I need to navigate to the frame's src url in order to traverse its child nodes.  The only way I've been able to do this is to use IHTMLDocument4::createDocumentFromUrl method.  I call this method and save the result, which should be the frame's DOM, to a PS variable.  I then call getElementById() and locate my anchor tag and save a reference to it in another PS variable, say $anchor.  I then try to call $anchor.click() and nothing happens.  That is my dilemma.

  • Thursday, November 05, 2009 8:10 AMMervyn ZhangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    I create a 2.html file:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML Transitional//EN"><META http-equiv="Content-Type" content="text/html; charset=utf-8">
    <HTML>
    <FRAMESET oncontextmenu="return false;" id="DESKTOPWRAPPERID" name="DESKTOPWRAPPERMAIN" frameSpacing="0" rows="460, *" frameBorder="0">
    <FRAMESET oncontextmenu="return false;" id="DESKTOPMAINID" name="DESKTOPMAIN" frameSpacing="2" frameBorder="0" cols="2200px, *">
    <FRAME id="leftFrameId" title="Navigation Frame" onfocus="top.gFocus=false;" name="leftFrame" frameSpacing="2" src="1.html" frameBorder="0" scrolling="no">
    </FRAME>
    </FRAMESET>
    </FRAMESET>
    </HTML>


    And then run the following commands:

    $ie = New-Object -comObject InternetExplorer.Application
    $ie.visible = $true
    $ie.navigate('e:\2.html')
    $ie.Document.body.innerHTML


    Got the following result:

    <FRAMESET id=DESKTOPMAINID oncontextmenu="return false;" frameSpacing=2 name=DESKTOPMAIN cols="2200px, *" frameBorder=0><FRAME i
    d=leftFrameId onfocus=top.gFocus=false; title="Navigation Frame" frameSpacing=2 src="1.html" frameBorder=0 name=leftFrame scroll
    ing=no></FRAMESET>

    Please try the same files on your side.

    Thanks.

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Thursday, November 05, 2009 4:13 PMdave_i_h Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I too get the same result.  However, my problem is when I try to navigate the html nodes directly under the frame with id=leftFrameId.  I did not post any HTML under this frame in my example above and I apologize for any confusion.  There is HTML that exists under this frame but I am unable to view or navigate it.

    And after writing the paragraph above I went and did what I should have done from the very beginning...I viewed the source of the page.  What I found is that the frame's content is dynamically constructed via javascript.  I feel like a heel not doing this before.

    Does anyone know how to go about automating a control's click event when the control is dynamically constructed (i.e. not sent as straightforward HTML from server to client)?  Should i open this question in a new post?
  • Friday, November 06, 2009 3:24 AMMervyn ZhangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

    It’s more of a Web development issue, it’s suggested to submit a new post in the MSDN forum to get more suggestions. They are the best resource for this kind of problem.

    MSDN Forum
    http://forums.microsoft.com/MSDN/default.aspx?SiteID=1

    Thanks.

    This posting is provided "AS IS" with no warranties, and confers no rights.