Page 1 of 1

Cann't access to frame at different domain when automate IE

Posted: 11 Apr 2019, 10:36
by xcracked
Hi, Everybody
These days, I have been learnt to Automate Internet Explorer. But, When I comes to get the element in frame/iframes at different domains, errors come out:ACCESSDENIED.And my method is:
objIE := WBGET()
objIE.document.frames["xxxx"].frames["xxxx"].document.getElementById........
this works when frames froms same domain, fail if froms different domain.
Any ideals will be helpful, sorry for my bad english.Thanks!

Re: Cann't access to frame at different domain when automate IE  Topic is solved

Posted: 11 Apr 2019, 11:12
by tank
you have to query for the document object from the documentElement

Code: Select all

IHTMLWindow2_from_IWebDOCUMENT( IWebDOCUMENT )
        {
        static IID_IHTMLWindow2 := "{332C4427-26CB-11D0-B483-00C04FD90119}"  ; IID_IHTMLWindow2
        return ComObj(9,ComObjQuery( IWebDOCUMENT, IID_IHTMLWindow2, IID_IHTMLWindow2),1)
        }

Code: Select all

frameDoc := IHTMLWindow2_from_IWebDOCUMENT( objIE.document.frames["xxxx"].documentElement )
Havent tested or done this in a while but that is what i recal

Re: Cann't access to frame at different domain when automate IE

Posted: 12 Apr 2019, 09:30
by xcracked
tank wrote:
11 Apr 2019, 11:12
you have to query for the document object from the documentElement

Code: Select all

IHTMLWindow2_from_IWebDOCUMENT( IWebDOCUMENT )
        {
        static IID_IHTMLWindow2 := "{332C4427-26CB-11D0-B483-00C04FD90119}"  ; IID_IHTMLWindow2
        return ComObj(9,ComObjQuery( IWebDOCUMENT, IID_IHTMLWindow2, IID_IHTMLWindow2),1)
        }

Code: Select all

frameDoc := IHTMLWindow2_from_IWebDOCUMENT( objIE.document.frames["xxxx"].documentElement )
Havent tested or done this in a while but that is what i recal
thanks, I will try this out!

Re: Cann't access to frame at different domain when automate IE

Posted: 13 Apr 2019, 00:53
by xcracked
Thanks,tank. Your code works nice.I have three frames at different domains,this is my code:

Code: Select all

rightFrameDoc := IHTMLWindow2_from_IWebDOCUMENT(objIE.document.frames["rightFrame"].document)
mainFrameDoc := IHTMLWindow2_from_IWebDOCUMENT(rightFrameDoc.frames["mainFrame"].document)
num := mainFrameDoc.document.frames["chiframe"].document.getElementById("capitalFl").Click()

Re: Cann't access to frame at different domain when automate IE

Posted: 13 Apr 2019, 11:58
by tank
glad it helped