html - Access to a webpage's frame document without navigating to this webpage -
the title might confusing, it's not impression. had previous post core problem deeper this.
basically have big code in navigate intranet webpage company ( let's call webpage start webpage).
i provide username , password information , click on "login" button. clicking on login button create new webpage in new window. call new webpage main webpage.
the main webpage contains important information want while start webpage useless me.
first challenge here "activate" or "select" main webpage since start webpage still activated. main webpage has url it's impossible directly navigate it, that's why talk "activation" or "selection" of webpage. managed of forum's post
if have questions let me know, it's not problem of post.
so main webpage activated, want click on element display more information. element embedded in frame postfachcontent. see main page html document overview , zoom on part click on.
in previous post mentioned above, tried got familiar "embedded" elements made task harder.
with of other members, figured out there 2 ways in postfachcontent frame :
by selecting child child frames :
set w = iewindowfromlocation(path) dim iedoc htmldocument set iedoc = w.document ' w called main webpage selected peviously in code dim subframescollection htmlwindow2 dim goodframe htmlwindow2 dim postfachcontent_frame htmlwindow2 set subframescollection = iedoc.frames ' length of 3 since contains 3 main frames set goodframe = subframescollection(1).frames ' contains 2 frames of "contentframe" frame length = 2 set postfachcontent_frame = goodframe(1) doc2 = postfachcontent_frame.document
but problem here once accessed frame got confused on how select element of table , click on it
- by "navigating" new webpage reduced version of main webpage focusing on frame interested in navigating main webpage url & contentframe.src (or postfachcontent.src).
but problem here, said above, can't navigate main webpage directly thought try declare new internetexplorer window , give location without navigating page ( doesn't work unfortunately). attempt below :
set w = iewindowfromlocation(path) dim iedoc htmldocument dim iedok htmldocument set iedoc = w.document dim contentframescollection ihtmlelementcollection dim contentframe htmlframeelement dim postfachcontentframescollection ihtmlelementcollection set contentframescollection = iedoc.getelementsbyname("contentframe") ' works , returns 1 item frame called contentframe, s collection of element containing 1 element ' msgbox contentframescollection.length ' returns 1 if not contentframescollection nothing set contentframe = contentframescollection(0) ' here isolate unique item contained in mainframescollection , store in single element called contentframe msgbox w.document.location & contentframe.src 'on error resume next set w2.document.location = w.document.location & contentframe.src 'msgbox err.description ' returns automation error unspecified error set iedok = w2.document set postfachcontentframescollection = iedok.getelementsbyname("postfachcontent") msgbox postfachcontentframescollection.length ' returns 0...oops end if
thanks reaching line , welcome !
here idea in code (this code untested). first navigate start page login. find main page. main page navigate first frame , second. after dom element should contain target button can clicked. hth
option explicit ' add reference microsoft internet controls (shdocvw) ' add reference microsoft html object library ' add reference microsoft shall controls , automation ' e.g. http://192.168.51.52:9999/someapp/login private const starturl string = "your start url" ' e.g. http://192.168.51.52:9999/someapp/content private const mainurl string = "your main url" sub clickinsideofframe() dim ie shdocvw.internetexplorer dim doc mshtml.htmldocument on error goto error_handler ' navigate start page set ie = new shdocvw.internetexplorer ie.visible = true ie.navigate starturl waitwhilebusy ie ' enter user name , password , login login ' switch main page set ie = iewindowfromtitle(mainurl) set doc = ie.document ' first find content frame , navige url of frame navigatetoframe ie, "frame[name='contentframe']" ' find postfachcontent frame , navige url of frame next navigatetoframe ie, "frame[name='postfachcontent']" ' dom document should contain button inside of ' postfachcontent frame doc.queryselector("input[type='button'][name='some-button']").click error_handler: if err.number <> 0 msgbox err.description, vbcritical, "error" ie.quit set ie = nothing end sub private sub waitwhilebusy(ie shdocvw.internetexplorer) while ie.busy or ie.readystate <> readystate_complete doevents wend end sub function iewindowfromtitle(stitle string) shdocvw.internetexplorer ' ... end function private sub navigatetoframe(ie shdocvw.internetexplorer, selector string) dim frame mshtml.htmlframeelement dim doc mshtml.htmldocument set doc = ie.document set frame = doc.queryselector(selector) if not frame nothing ie.navigate mainurl & frame.src waitwhilebusy ie exit sub end if err.raise vbobjecterror + 513, "navigatetoframe", "frame not found selector '" & selector & "'." end sub private sub login() ' ... end sub
Comments
Post a Comment