I am attempting to write a function to dig through the frames in a webpage and take an action with an element once found. This seems to work for some elements on the page, but not all. Specifically, after clicking a button "search", another frame appears (does not appear to be new window, and the current page does not navigate or change in any other way).
It is the elements in this newly visible frame that I cannot seem to access. I tried getting a new document object from the page but this didnt help. Futher testing that option seems to indicate the frame structure is not changing while interacting with the page up to this point (maybe its an invisible frame already there before i click 'search' and get the popup frame). Im still digging at this problem, however I havent made any progress in a few hours and Im wondering if my overall function is not digging through the nested frames correctly.
Here is a sample script that calls the function, but the website is not accessible from the internet. When i run this script on my computer, i get the msgbox for searchstring1 but not for searchstring2. There are at least 14 frames, with some frames having several nested frames (i think). I understand this may be extremely slow (it is), but if i could wrap my head around this issue i can look for forms or tag names instead of 'all' im thinking, and that should give my loops much smaller collections to work with.
Code: Select all
comobjerror(false)
wb := IEGet("INTERNAL SITE")
frames := wb.document.frames
framefunc(frames)
framefunc(frames)
{
searchstring1 := "Search" ;i can click button with innertext 'search'
searchstring2 := "searchText" ;i cannot input text into text field named 'searchText'
loop % frames.length
{
frame := frames[a_index-1]
element_count := frame.document.all.length
loop % element_count
{
innertext := frame.document.all[a_index-1].innertext
element_name := frame.document.all[a_index-1].name
element_id := frame.document.all[a_index-1].id
if(innertext=searchstring1)
{
msgbox % "Found element id '" . element_id . "'`nname '" . element_name . "'`ninnertext '" . innertext . "'"
;frame.document.all[a_index-1].click()
}
if(element_name=searchstring2)
{
msgbox found by %element_name%
;frame.document.all[a_index-1].value := "anystring"
}
}
if frames[a_index-1].length
{
framefunc(frames[a_index-1].frames)
}
}
return
}
IEGet(Name="") ;Retrieve pointer to existing IE window/tab
{
IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
: RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
For wb in ComObjCreate( "Shell.Application" ).Windows
If ( wb.LocationName = Name ) && InStr( wb.FullName, "iexplore.exe" )
Return wb
}
iWB2 Learner info:
No problem here - there is actually one more set of two frames i have a screenshot of but could only attach 3 total, no issue here anyway
Problem here -