Sign in to follow this  
Followers 0
njahncke

Creating an object reference to an IFrame element

5 posts in this topic

Howdy everyone,

I'm facing what I assume must be a problem with a very simple solution: I have a page that contains two IFrames and I need to create an object reference to a <tr> element within one of the IFrames. Here's a basic sketch of the process...

; The scene opens with an existing browser object, passed
; on by earlier operations. It is in a known good state.
_IELoadWait($objBrowserEditDevice)

; This is where I have attempted  in every way I can think of  to create an object reference
; to the IFrame element I need that I can subsequently act on using _IEGetObjById
$objBrowserFrameDeviceList = _IEFrameGetObjByName($objBrowserEditDevice,"machineTab_frame1")
; The id attribute of the IFrame is "machineTab_frame1". Apparently, that is supposed to work.
; For me, it does not. It spits out:
; If String($o_object.document.body.tagName) = "FRAMESET" Then 
; If String($o_object.document^ ERROR

; I have tried every way I can think of to create a workable reference to the IFrame, all to no avail.
; Unfortunately, I can't just instantiate a new browser object and direct it to the src of the IFrame;
; the point of this script is to operate on the elements within the frame in their native context.

; The remainder here illustrates essentially what I would like to do with the reference:
; examine a series of objects (rows in a table) in turn, exiting the loop after I find
; the one I'm after. I'm sure there's a better way to do this, but whatever lol...
; Logic suggestions are welcome too!
$rowIndex = 0
While 1
    $objLinkDevice = _IEGetObjById($objBrowserFrameDeviceList,"Device_r_" & $rowIndex)
    If Not IsObj($objLinkDevice) Then
        MsgBox(0,"","Device not found!") ; Temporary error handling
        Exit
    ElseIf StringInStr($objLinkDevice.innerHTML,$deviceName) <> 0 Then
        Record("Target Device found at rowIndex: " & $rowIndex)
        ExitLoop
    EndIf
    $rowIndex += 1
WEnd

; This is a custom function that just digs out the position of the object and clicks it.
ClickObject($objLinkDevice,14,41)

So there you have it... I will truly appreciate any advice/guidance/et cetera.

Please bear in mind that I had to edit this source before I posted it to avoid NDA issues.

Any $var mismatches exist because I missed them here, not in my actual code.

Thanks for your time!

Share this post


Link to post
Share on other sites



Hopefully you are running this from SciTe -- whe is written to the console? Also suggest you add _IEErrorHandlerRegister() near the top of you code.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Hi Dale. Thanks for the response! Please let me begin by offering my profound thanks for the work you've saved all of us by creating the _IE API. Honestly, I can't thank you enough; it's so great to have.

I have been running this from SciTE, and I probably should have clarified: the

If String($o_object.document.body.tagName) = "FRAMESET" Then

If String($o_object.document^ ERROR

error I'm seeing is what the console displays when I attempt to create a frame object using _IEFrameGetObjByName(). I have been using _IEErrorHandlerRegister() off and on throughout this process, but all I've been seeing has seemed to me to be rather misleading, as I'm getting "Access is Denied" errors. Based on the many other posts I've read in researching a fix for this, those are usually caused by cross-domain frame references, which is not the case here. I might just be running into a problem caused by the design of the page I'm forced to interact with; it's rather heavy on the client-side scripting.

However, my real question is this: if I instantiate a frame object using either the _IEFrameGetObjByName() or by index with the _IEFrameGetCollection() method, should I then be able to access the objects that object contains by using _IEGetObjById(), or am I just completely off base? I guess I just don't really know if the frame object I'm creating is actually a window object or not. I've also tried attaching to one of the IFrames using its URL, but that didn't work either. Just a shot in the dark.

Thanks again, Dale. I appreciate your help. Let me know if you need any further information.

Share this post


Link to post
Share on other sites

Hi Dale. Thanks for the response! Please let me begin by offering my profound thanks for the work you've saved all of us by creating the _IE API. Honestly, I can't thank you enough; it's so great to have.

You're welcome - and thanks, I appreaciate the comments.

I have been running this from SciTE, and I probably should have clarified: the

If String($o_object.document.body.tagName) = "FRAMESET" Then

If String($o_object.document^ ERROR

error I'm seeing is what the console displays when I attempt to create a frame object using _IEFrameGetObjByName().

I've seen this reported a couple of times before and I can do a better job of trapping and reporting this error. If you are able to construct a reproducer it would be appreciated.

I have been using _IEErrorHandlerRegister() off and on throughout this process, but all I've been seeing has seemed to me to be rather misleading, as I'm getting "Access is Denied" errors. Based on the many other posts I've read in researching a fix for this, those are usually caused by cross-domain frame references, which is not the case here. I might just be running into a problem caused by the design of the page I'm forced to interact with; it's rather heavy on the client-side scripting.

In addition to the standard cross domain frame cause for an Access Is Denied error, I have also seen this once with Gmail and an AJAX method that I did not expect to create such an issue. I didn't have the time to investigate the issue at the time and don't recall how I found it. One thing to consider is that it _could_ be a timing issue -- you might want to try to techniques of insuring that the page has quiesced and see if it is transient.

However, my real question is this: if I instantiate a frame object using either the _IEFrameGetObjByName() or by index with the _IEFrameGetCollection() method, should I then be able to access the objects that object contains by using _IEGetObjById(), or am I just completely off base? I guess I just don't really know if the frame object I'm creating is actually a window object or not. I've also tried attaching to one of the IFrames using its URL, but that didn't work either. Just a shot in the dark.

Yes, this is exactly as it should work. You can check your object with ObjName to insure it is what you expect it to be. One confusing thing about frames is that there are two kinds of references - a frame as tag and a frame as window. A frame as tag gives you access to the frame or iframe tag properties like src, height, width etc. A frame as window is a document container and can be used nearly interchangably with a typical $oIE type browser object.

The Access Is Denied error is likely very significant. There is more information here: http://msdn2.microsoft.com/en-us/library/ms533047.aspx

Please let me know what progress you make on this.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Hey Dale. I think you're right: my assumption at this point is that some aspect of the client-side processing this page performs is resulting in the "Access is denied" error.

For now, I've had to just hack a workaround (I'm not validating the content of the object I'd like to examine, just selecting it via a totally unrobust method I hesitate to share lol...).

This will work for my purposes for the time being, due to other priorities, but I'll be returning to this later in the week. As soon as I do, I'll get some more information to you, including a reproducer for each of the issues I witness as I go, when possible.

Thanks again for all your help, Dale.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0