Jump to content

_IEcreateEmbedded source problem...


Recommended Posts

Hey guys, I've got yet another question. I searched around and can't seem to find anyone else with the same problem. Basically, I have an embedded IE object, I have it navigate to a page, and want to read the source. When I try and read the source, IE.au3 gives me an error.

Here is a reproducer:

#include <IE.au3>
#include <String.au3>
#include <GUIConstants.au3>

$hwnd = GUICreate("test", 500, 500, -1, -1, -1)
Opt("GUIOnEventMode", 1)
$oIE = _IECreateEmbedded()
GUICtrlCreateObj($oIE, 10, 30, 500 - 20, 500 - 40)
GUISetState()
_IENavigate($oIE, "about:blank")
Sleep(1000)
_IEDocWriteHTML($oIE, '<frameset id=mainset cols="10,10">' _
         & '<frame name=frame1 src="http://www.google.com">' _
         & '<frame name=frame2 src="http://www.google.com">')
_IEAction($oIE, "refresh")
Global $Frame = _IEFrameGetObjByName($oIE, "frame1")
$framesrc = _IEDocReadHTML($Frame) ;This seems to be the line that makes the error.
While 1
    Sleep(1000)
WEnd

The error is:

CODE
C:\PROGRA~1\AutoIt3\Include\IE.au3 (2214) : ==> The requested action with this object has failed.:

Return $o_object.document.documentElement.outerHTML

Return $o_object.document^ ERROR

Is there no .outerHTML in a embedded IE? what am I doing wrong?

Many thanks!

Brick

Edited by Brickoneer
Link to comment
Share on other sites

Use _IEErrorHandlerRegister() -- you should see an Access is denied error at the console.

This is a cross-site frame secuity restriction. You cannot access the google frame from script because its parent frame is not on google.com

Sorry, this is one of the areas where making the browser object secure from hackers limits its functionality.

Dale

Edit: typo

Edited by DaleHohm

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

Link to comment
Share on other sites

Use _IEErrorHandlerRegister() -- you should see an Access is denied error at the console.

This is a cross-site frame secuity restriction. You cannot access the google frame from script because its parent frame is not on google.com

Sorry, this is one of the areas where making the browser object secure from hackers limits its functionality.

Dale

Edit: typo

Thanks for the very informative reply!

I assume you mean it is seeing the GUI as a parent frame, and triggering the cross-site security restrictions?

Is there any way around this? If not, doesn't that mean an embedded IE browser using frames is almost impossible to automate/manipulate?

many thanks,

brick

Link to comment
Share on other sites

I assume you mean it is seeing the GUI as a parent frame, and triggering the cross-site security restrictions?

No, it's seeing the frameset of your local HTML as the parent. Your local HTML/frameset is not from google, so putting google frames inside it makes it cross-site.

Is there any way around this? If not, doesn't that mean an embedded IE browser using frames is almost impossible to automate/manipulate?

Simply create two embedded browser objects and they will very scriptable:

#include <IE.au3>
#include <String.au3>
#include <GUIConstants.au3>

$hwnd = GUICreate("test", 600, 500, -1, -1, -1)
Opt("GUIOnEventMode", 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
$oIE_1 = _IECreateEmbedded()
$oIE_2 = _IECreateEmbedded()
GUICtrlCreateObj($oIE_1, 10, 10, 285, 480)
GUICtrlCreateObj($oIE_2, 305, 10, 285, 480)
GUISetState()
_IENavigate($oIE_1, "http://www.autoitscript.com", 0)
_IENavigate($oIE_2, "http://www.google.com", 1)
ConsoleWrite(_IEDocReadHTML($oIE_2) & @LF)

While 1
    Sleep(20)
WEnd

Func _Quit()
    Exit
EndFunc

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...