Nested iFrames IE COM

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
timelizards
Posts: 20
Joined: 11 Sep 2015, 21:00

Nested iFrames IE COM

Post by timelizards » 09 Dec 2015, 15:12

*fixed subject 12/9

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 -
iwb21.png
iwb21.png (13.53 KiB) Viewed 2116 times
iwb22.png
iwb22.png (2.6 KiB) Viewed 2116 times
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 -
IWB2.png
IWB2.png (12.52 KiB) Viewed 2116 times

timelizards
Posts: 20
Joined: 11 Sep 2015, 21:00

Re: Nested iFrames IE COM

Post by timelizards » 09 Dec 2015, 15:25

tried pre-loading the textbox with a value "LOOKFORME" then added the following code to with no success

Code: Select all

element_value := frame.document.all[a_index-1].value

if(element_value="LOOKFORME")
{
	MSGBOX found element by value %element_value%
	
}

User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: Nested iFrames IE COM

Post by Blackholyman » 09 Dec 2015, 15:44

Best bet is that you need to query the frames

Try the search at the top of ahkscript.org for "ie error" there is a topic where i work though how to do it with another user...
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:


Post Reply

Return to “Ask for Help (v1)”