Jump to content


Photo

Assistance clicking SUBMIT button via COM.


  • Please log in to reply
20 replies to this topic

#1 Thermopyle

Thermopyle
  • Members
  • 135 posts

Posted 11 April 2012 - 02:30 PM

I'm trying to click the Submit button on this site: <!-- m -->http://www.dell.com/... ... tSelection<!-- m -->

iWebBrowser shows the button as being in the frame iFramePSHost, with innertext=Submit. OuterHTML = <SPAN class=uif_m_inner>Submit </SPAN>

Here's the code I'm trying to use:

url = http://www.dell.com/support/drivers/us/en/04/DriversHome/NeedProductSelection 
  pwb :=   ComObjCreate("InternetExplorer.Application")
  ;navigates to the url
  pwb.Navigate(url) 
  pwb.visible := true
  While   pwb.readyState <> 4 || pwb.document.readyState <> "complete" || pwb.busy 
    Sleep, 10 
  frame :=   pwb.document.all["iFramePSHost"].contentWindow
  frame.document.all["TheProductSelectorResultsModel_ServiceTagCode"].value := Tag
  link = "Submit"
  frame.document.all[link].click(), frame.document.all[link].fireEvent("onclick")
I know the frame is being targeted correctly because the text field just above the Submit button (and in the same frame) is being assigned correctly. I've also tried using this script from the COM guide:
Links := Frame.Document.Links
Loop % Links.Length
   If (Links[(A_Index - 1)].InnerText = "Submit") {
      Links[(A_Index - 1)].Click()
      break
   }
This code doesn't work on this page. I've also tested it by adding:
msgbox % Links[A_Index-1].InnerText
This reveals that the only link recognized within the frame is the Where To Find Your Service Tag link--the Submit button is not recognized as a link.

I'm sure this is super-simple, but I've been trying to figure out what I'm doing wrong with this for a couple of hours now. Can somebody take a look at the page and this code and give me an idea of what the problem is?

Thanks!

#2 sinkfaze

sinkfaze
  • Moderators
  • 6077 posts

Posted 11 April 2012 - 06:56 PM

I'm a bit weary of your outerHTML report since your code indicates you're trying to fire an onclick event that isn't there. Are you sure that's all the info there is for that button?

Additional question: I see that the Submit button isn't enabled until you enter text in the prior edit field. Do you have a JS event for that edit box that needs to be fired to enable the button?

#3 crazyace

crazyace
  • Members
  • 155 posts

Posted 11 April 2012 - 07:41 PM

sinkfaze,

We have been using the iWB2 Learner tool to pull that information. I tried to look for any JS that could help me out with giving you an answer, but I wasn't able to find that info with the iWB2 tool. I know that the page it's self will have some JS and jQuery

#4 sinkfaze

sinkfaze
  • Moderators
  • 6077 posts

Posted 11 April 2012 - 08:21 PM

Post the outerHTML for the edit field you're sending the text to.

#5 crazyace

crazyace
  • Members
  • 155 posts

Posted 11 April 2012 - 09:01 PM

Here is everything for the input box.

<INPUT id=TheProductSelectorResultsModel_ServiceTagCode maxLength=11 value=5K84WD1 name=TheProductSelectorResultsModel.ServiceTagCode jQuery15103328811952422851="15">


#6 sinkfaze

sinkfaze
  • Moderators
  • 6077 posts

Posted 11 April 2012 - 09:05 PM

When you place the text in the edit box using the script, does it enable the button?

#7 crazyace

crazyace
  • Members
  • 155 posts

Posted 11 April 2012 - 09:10 PM

Yes sir, but we are not able to find anything to help us make the button fire.

#8 BigVent

BigVent
  • Moderators
  • 194 posts

Posted 11 April 2012 - 09:19 PM

#SingleInstance Force
onexit, exitsub

pwb := ComObjCreate("InternetExplorer.Application")
    pwb.Visible := true ; show IE
	pwb.Navigate("http://www.dell.com/support/drivers/us/en/04/DriversHome/NeedProductSelection")
	
	while pwb.ReadyState <> 4
		continue

Tag := "72759"  ;change accordingly as this is totally a made up #		
		
frame := pwb.document.all["iFramePSHost"].contentWindow
frame.document.all["TheProductSelectorResultsModel_ServiceTagCode"].value := Tag
  
find_it = 1
loop,
{
text := frame.document.all[find_it].OuterHTML
if (text = "<SPAN class=uif_m_inner>Submit </SPAN>")
{
	frame.document.all[find_it].click
	break
}
else
   find_it++
}

msgbox %text% found on Index %find_it%

Esc::
exitsub:
        pwb.Quit
        pwb := ""
Exitapp


:D

#9 crazyace

crazyace
  • Members
  • 155 posts

Posted 11 April 2012 - 09:22 PM

Thanks BigVent,

That works like a charm :-)

That came back with
---------------------------
New AutoHotkey Script.ahk
---------------------------
<SPAN class=uif_m_inner>Submit </SPAN> found on Index 96
---------------------------
OK   
---------------------------


#10 BigVent

BigVent
  • Moderators
  • 194 posts

Posted 11 April 2012 - 09:50 PM

Yw! Glad to help!

#11 sinkfaze

sinkfaze
  • Moderators
  • 6077 posts

Posted 11 April 2012 - 09:52 PM

The index number is likely to be dynamic so I wouldn't hard code that number. This should be a good cleanup of BigVent's loop:

loop
{}	Until	(frame.document.all.tags["span"].item[[color=#FF0000](i :=	A_Index-1)[/color]].OuterHTML="<SPAN class=uif_m_inner>Submit </SPAN>")
frame.document.all[[color=#FF0000]i[/color]].click


#12 Thermopyle

Thermopyle
  • Members
  • 135 posts

Posted 11 April 2012 - 10:53 PM

Sinkfaze, BigVent, thanks for all the assistance!

Sinkfaze, I ended up using your code with a bit of modification to get it to work (it didn't as-is). Here was the result:
loop
	{}   Until   (frame.document.all[i].OuterHTML="<SPAN class=uif_m_inner>Sutbmit </SPAN>")
	frame.document.all[i].click
It's slower than I'd like (it takes about 16 seconds from entering the tag in the GUI that triggers all this to having the page come up, the tag inserted, the Submit button clicked, and the resulting page to come up), but that's a limitation of the site to be honest so there's nothing we can do about that. This code works perfectly--I'll know in the future to look for OuterHTML and deal with those items as well. This is the first time I've had to mess with it so it's never come up before.

Thanks again for the help!

#13 sinkfaze

sinkfaze
  • Moderators
  • 6077 posts

Posted 11 April 2012 - 11:32 PM

Just FYI, using OuterHTML in this way is very inefficient and should only be used when all other methods won't work.

#14 Thermopyle

Thermopyle
  • Members
  • 135 posts

Posted 12 April 2012 - 12:04 AM

Is there another way you can see to do it in this?

#15 jethrow

jethrow
  • Fellows
  • 2549 posts

Posted 12 April 2012 - 12:22 AM

Did you try this?
frame.document.all.btnSubmit[0].click