excel - Automate IE with VBA - Click Javascript Link (no Anchor tag) -
our company uses browser-based program business operations. goal grab data out of system automatically.
the site uses frames pretty heavily, i'm doing pretty decently handling that. problem in front of me navigating screen on data housed.
the link coded in javascript, , don't see anchor tag (the image +/-, or invisible spacing):
source code
<div id='nav_4' atag='atarget' title='target' aurl="javascript:top.aaa.submitpage('navigateto','~/apages/apage.aspx?uc=a')"> <img alt='' style="margin-left:0px; width:0px "/> <img src='/a/a.axd?d=a' alt='(collapsed)' aaltx='(expanded)' imgtype='exp' /> <img alt=''style='width:5px; visibility:hidden;'> <span atxt='1' class=" breadcrumbtreeitem"> target </span></div>
since couldn't tag, or search document links, instead tried find span tag contained "target" , try activate it.
here working code! (i5 iterator)
set ie = getopeniebyurl("https://aaa.com/aaa.htm") fiter = 0 each frmset in ie.document.getelementsbytagname("frame") if left(frmset.src, 7) = "aaa/aaa" myframe = f_iter exit end if f_iter = f_iter + 1 next ie i5 = 0 ie.document.frames(myframe).document.all.tags("span").length - 1 .document.frames(myframe).document.all.tags("span").item(i5) if instr(.innertext, "target") > 0 .click exit end if end next i5 end
additionally, in module, add code:
'finds open ie site checking url function getopeniebyurl(byval i_url string) internetexplorer dim objshellwindows new shellwindows 'ignore errors when accessing document property on error resume next 'loop on shell-windows each getopeniebyurl in objshellwindows 'if document of type htmldocument, ie window if typename(getopeniebyurl.document) = "htmldocument" 'check url if left(getopeniebyurl.document.url, 30) = left(i_url, 30) 'leave, found right window exit function end if end if next end function
looking @ code, see
elementlist = ie.document.frames(myframe).document.getelementsbytagname("span")
which should used set
, so:
set elementlist = ie.document.frames(myframe).document.getelementsbytagname("span")
as far error on dim
line, can define object
or variant
, should still work, since type being returned getelementsbytagname
should still valid.
responding update, click button, use:
set objbutton = iepage.getelementbyid("buttonname") iepage.onmousedown 'there js code catches these actions validation, artificially trigger them on page. requirements may vary. objbutton.focus objbutton.click
mixing code, put (untested):
with ie i5 = 0 ie.document.frames(myframe).document.all.tags("span").length - 1 .document.frames(myframe).document.all.tags("span").item(i5) if instr(.innertext, "target") > 0 debug.print .innertext ie.document.frames(myframe).document.onmousedown .focus .click exit end if end next i5 end
Comments
Post a Comment