PDA

View Full Version : Solved: Webbrowser Frames



khalid79m
06-09-2011, 05:14 AM
Sub Open_Website()
Set Iexplorer = CreateObject("InternetExplorer.Application")
Iexplorer.Visible = True
Iexplorer.Navigate "http://zz/ultra/search/Search_Frames.aspx?FormName=etmSessionQuery&WorldName=etm"
Do While Iexplorer.Busy And Not Iexplorer.ReadyState = 4:
Application.Wait (Now + TimeValue("0:00:02"))
DoEvents
Loop
For x = 0 To Iexplorer.Document.frames.Length - 1
Debug.Print Iexplorer.Document.frames(x).Name
MsgBox Iexplorer.Document.frames(x).Name
Next x
End Sub

Hi I am trying to launch a internal webbased media player, which allows thie business to sample calls, I need to launch this from excel which is is easy peasy, and now i have got to the difficult bit selcting frames and relevent boxes/controls to fill in.

The code above launches the page.. i have ommitted the true address, you wont be able to access it anyway, and filters through the frame names, the one i need is called FR_Search, i need help now to do 2 things

1.st how do i select this specific frame, so I can then use send keys ?

2nd how do I find all the controls within the frame?

Thanks

Shred Dude
06-12-2011, 09:54 AM
First of all, avoid using Send Keys.

To navigate to the controls within a frame, use a syntax similar to this:

Iexplorer.document.frames(1).getelementbyid("desired_control_name").[property to update].value = "xyz"


or create an Element collection and populate with all the type of controls within the frame you're intereseted in and then you can iterate the collection as needed.

Dim colFrameControls as IHTMLElementcollection
set colFrameControls = Iexplorer.document.frames(x).getlementsbytagname("control type you want")
for each ctl in colFramecontrols
Debug.Print ctl.xxx
next ctl

khalid79m
06-14-2011, 08:56 AM
Dim colFrameControls As IHTMLElementcollection

It fails on this .. do i need to set something up?

Shred Dude
06-14-2011, 11:15 AM
You'll need to set a reference the HTML library.

khalid79m
06-14-2011, 01:14 PM
Hi I have attached the source code for the webpage, I want to be able to as a starter (so i can see how it can be done) to select the radio button

Between these dates and times:

and then be able to fill in the date and times and click search.

Can anyone help with this , I am new to this never done this before.

Shred Dude
06-14-2011, 01:49 PM
Without having access to the site I'm not going to try to code it. You'll need to examine the source and identify the relevant items. This page makes heavy use of javascript, so you're probably going ot have to play with invoking the onclick events of some of these controls in order for the scripts to run and do whatever they do as a user would be updating the form.

For example, the first radio button looks like this:

<input id="NewDynamicFormDisplay1_MainSection_catDateRangeCalls__ctl2_trsDateRangeCall s__ctl1" type="radio" name="NewDynamicFormDisplay1:MainSection:catDateRangeCalls:_ctl2:trsDateRangeCall s:RadioButtons" value="NewDynamicFormDisplay1_MainSection_catDateRangeCalls__ctl2_trsDateRangeCall s__ctl1_RadioPanel" checked="checked" onclick="RadioPanelShowHide(this,'NewDynamicFormDisplay1_MainSection_catDateRangeCal ls__ctl2_trsDateRangeCalls__ctl1_PanelCheckBox')">

After obtaining a reference to the HTML document you could try something like:

mydoc.getelementbyid("NewDynamicFormDisplay1_MainSection_catDateRangeCalls__ctl2_trsDateRangeCall s__ctl1")
.checked="checked"


but I have a feeling that that's not going to get you to where you need to be because of the javascript that gets invoked by the onclick events which appear to be toggling on and off the visibility of date picker controls or the text box shown in your example based on whichever radio button is selected.

So you could try things like using the FireEvent method of a control to advance your script with something like:

mydoc.getelementbyid("NewDynamicFormDisplay1_MainSection_catDateRangeCalls__ctl2_trsDateRangeCall s__ctl1").fireevent("onclick")

'then do a loop to wait for readystate complete on the page...

khalid79m
06-15-2011, 03:53 AM
Sub ContolVerint()
Set Iexplorer = CreateObject("InternetExplorer.Application")
Iexplorer.Visible = True
Iexplorer.Navigate "http://ss/ultra/search/Search_Frames.aspx?FormName=etmSessionQuery&WorldName=etm"
Do While Iexplorer.Busy And Not Iexplorer.ReadyState = 4:
Application.Wait (Now + TimeValue("0:00:02"))
DoEvents
Loop
Iexplorer.Document.getelementbyid("NewDynamicFormDisplay1_MainSection_catDateRangeCalls__ctl2_trsDateRangeCall s__ctl1").fireevent ("onclick")
End Sub

Sorry mate im new to all of this, i have tried the above but got the following message

Run-Time error '91':
Object Variable or With block Variable not set