Followers 0

# Internet explorer script

## 19 posts in this topic

Hey everyone...

I'm having trouble with the IEformelementoptionselect command. I'm trying to use it to select an drop down menu from a website (very similarly to the example in help file). No matter what I do I can't seem to match by text or value. Ultimately what I'm doing is having someone paste a user ID into a box manually, press F7 and several other field on the website will populate. Unfortunately you won't be able to match exactly my error since you have to have access to the website.

Here is my code

;cs  Type user's UID into requester name field and press F7
;    Update .ini files manually
;ce

#include <IE.au3>
HotKeySet ("{F7}", "EMSWrite")
HotKeySet ("{ESC}", "EMSExit")
;;;;;;;;;;
While 1
Sleep(500)
WEnd
;;;;;;;;;;
Func EMSWrite()
$oIE = _IECreate("xxxxx") Sleep (5000);Used for testing$oForm = _IEFormGetObjByName ($oIE, "Form1")$oText = _IEFormElementGetObjByName ($oForm, "_ctl1:txtReqName")$oUID = _IEFormElementGetValue ($oText)$oReqFULLName = _IEFormElementGetObjByName ($oForm, "_ctl1:txtReqName")$oReqPhone = _IEFormElementGetObjByName ($oForm, "_ctl1:txtReqPhone")$oCostCenter =  _IEFormElementGetObjByName ($oForm, "_ctl1:txtCostCenter")$oFloor = _IEFormElementGetObjByName ($oForm, "_ctl1:txtFloor")$oSite = _IEFormElementGetObjByName ($oForm, "_ctl1:lstSites") ;;;;;;;;;;$ReqFname = IniRead(@ScriptDir&"\Inifiles\"&$oUID&".ini","EMS_Info","ReqFname","")$ReqLname = IniRead(@ScriptDir&"\Inifiles\"&$oUID&".ini","EMS_Info","ReqLname","") ;;;;;;;;;; BELOW, To join first name and last name$ReqFULLName = $ReqFname&" "&$ReqLname
$ReqPhone = IniRead(@ScriptDir&"\Inifiles\"&$oUID&".ini","EMS_Info","ReqPhone","")
$CostCenter = IniRead(@ScriptDir&"\Inifiles\"&$oUID&".ini","EMS_Info","CostCenter","")
$Floor = IniRead(@ScriptDir&"\Inifiles\"&$oUID&".ini","EMS_Info","Floor","")
$Site = IniRead(@ScriptDir&"\Inifiles\"&$oUID&".ini","EMS_Info","Site","")
;;;;;;;;;;
MsgBox (0,"", $Site);Used for testing _IEFormElementSetValue ($oReqFULLName, $ReqFULLName) _IEFormElementSetValue ($oReqPhone, $ReqPhone) _IEFormElementSetValue ($oCostCenter, $CostCenter) _IEFormElementSetValue ($oFloor, $Floor) Sleep(500);tried adding sleep before selecting menu dropdown ;_IEFormElementOptionselect ($oSite,4, 1, "byIndex") WORKS
_IEFormElementOptionselect ($oSite, "NYM234(270 Park Avenue)", 1);Doesn't work EndFunc ;;;;;;;;;; Func EMSExit() Exit EndFunc The problem line of code is really the last _IEForm line. What you see above is exaclty how it looks in the dropdown menu, and here is the source code of the site in regards to the drop down menu... <option value="174">NYM234(270 Park Avenue)</option> I've tried a bunch of different things, matching text or value doesnt seem to work but matching index does(see line above). I've been going at this for a while and I entirely expect it to be a stupid answer but go easy.... And while I'm asking, how do you use an exsisting webpage instead of _IECreate(and can you give an example)? Since by the nature of my script the website will exsist already I don't want to create another. I tried a couple things but couldn't figure out how. In the end I admit I don't fully understand how IE.au3 works; so thats probably where I'm in trouble. If you need more info about the website or anything let me know I'll post up more of the source code or whatever. Any help is as always greatly appreciated. Thanks, Andrew PS Don't bash me too hard for not using IniReadSection as opposed to IniRead... I'm still learning arrays... :"> While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd #### Share this post ##### Link to post ##### Share on other sites I've tried a bunch of different things, matching text or value doesnt seem to work but matching index does So wouldn't a simple solution be to use indexing? lol And while I'm asking, how do you use an exsisting webpage instead of _IECreate(and can you give an example)? Since by the nature of my script the website will exsist already I don't want to create another. I tried a couple things but couldn't figure out how. In the end I admit I don't fully understand how IE.au3 works; so thats probably where I'm in trouble. You can use _IECreate($obj, 1) to try and attach to an existing url, and if it fails it will create the object. Or use _IEAttach to just attach to the url.

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]

##### Share on other sites

Mike's feedback is all on the money.

Regarding your example, byValue is the default mode, so you would need to specify "174" (note that you may need the "" to force it to be a string - I don't recall whether I do this conversion for you, but you would have trouble with things like 007 without the quotes).

Since byText is NOT the default, your example would need to be:

_IEFormElementOptionselect ($oSite, "NYM234(270 Park Avenue)", 1, "byText") Does this help? Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl Automate input type=file (Related) SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble #### Share this post ##### Link to post ##### Share on other sites #4 · Posted (edited) So wouldn't a simple solution be to use indexing? lol Haha I probably should have said why I can't. Theres 2 reasons, one is because theres a lot of menu items in the dropdown, so its not exactly efficient to do that. The other is the ini files I'm using to populate the site will be created by people with no coding experience, and I know they won't figure out the value for the indexing... if that makes sense You can use _IECreate($obj, 1) to try and attach to an existing url, and if it fails it will create the object. Or use _IEAttach to just attach to the url.

Ok cool I try that.

Any suggestions on text matching(which is the preferable way)?

EDIT - Dale: I just posted this before seeing your reply I'll let you know soon, unfortunately I can't log into the website from home so I'll tell you tomorrow, but I'm almost positive I had used the correct syntax before, but I'll double check. Thanks

Edited by someone

While ProcessExists('Andrews bad day.exe')
BlockInput(1)
SoundPlay('Music.wav')
SoundSetWaveVolume('Louder')
WEnd

##### Share on other sites

#5 ·  Posted (edited)

uu

Since byText is NOT the default, your example would need to be:

_IEFormElementOptionselect ($oSite, "NYM234(270 Park Avenue)", 1, "byText") Does this help? Dale No that doesn't work either. This is exactly the source code...(I posted 2 lines so you can maybe get a better idea of how the form is setup) <option value="658">NYM219(214 Broadway)</option> <option value="174">NYM234(270 Park Avenue)</option> And this is exactly how the option looks in the drop down menu... NYM234(270 Park Avenue) EDIT - Nevermind, the 174 is the value... In the source code, what is the 174 referencing? Its not the nuber I need to make indexing work, but also copying the whole text after the = sign and using it wth byText doesn't work either _IEFormElementOptionselect ($oSite, '""174"">NYM234(270 Park Avenue)',1,"byText")

Any thoughts?

PS I haven't upgraded to the newest beta yet (Nov 18 release). If I should for this script let me know.

Thanks

EDIT-

I'm starting to understand using IE.au3 more, and this might help figure out how to make this work. In IE builder(great tool by the way) under html elements this is how the table looks

396 SELECT _ctl1:lstSites _ctl1_lstSites

397 OPTION Option index: 0

Value:

Selected: -1

398 OPTION Option index: 1

Value: 1169

Selected: 0

Theres a lot of entries for all the sites, but this is how they are all setup. Sorry I didn't give everyone that info earlier

Edited by someone

While ProcessExists('Andrews bad day.exe')
BlockInput(1)
SoundPlay('Music.wav')
SoundSetWaveVolume('Louder')
WEnd

Are you getting an IEFormElementSelectOption error, or instead are you getting an IEFormElementGetObjByName error (specifically from the $oSite search)? It would help to have a look at the entire source, could you specify the url or provide the source? IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] #### Share this post ##### Link to post ##### Share on other sites Just wondering, what is the ID for the combo box? Try using that instead of the option value. The option value has to do with what is returned to the server on submit. #### Share this post ##### Link to post ##### Share on other sites #8 · Posted (edited) Unfortunately you need a password for the site, but I'll attach the source code. Its not huge but its fairly big. I'm not getting any errors at all. Once I see you downloaded the file I'm going to take it off... just for minor privacy concerns. If anyone needs it I'll give it to them I just don't want to leave it up there Edited by someone While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd #### Share this post ##### Link to post ##### Share on other sites Just wondering, what is the ID for the combo box? Try using that instead of the option value. The option value has to do with what is returned to the server on submit. The ID for the box I'm using is _ctl1_lstSites , which is the same as the name. Thats what you mean right? While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd #### Share this post ##### Link to post ##### Share on other sites Once I see you downloaded the file I'm going to take it off... just for minor privacy concerns. If anyone needs it I'll give it to them I just don't want to leave it up there Downloaded. IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] #### Share this post ##### Link to post ##### Share on other sites I'm not getting any errors at all. Are you running it through Scite? You should be getting an error, even if it's not terminal. IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] #### Share this post ##### Link to post ##### Share on other sites #12 · Posted (edited) Hmm no I'm not getting any errors, and yeah using Scite. In case something changed or whatever I'm posting my code again.. ;cs Type user's UID into requester name field and press F7 ; Update .ini files manually ;ce$g_szVersion = "EMSini"
If WinExists($g_szVersion) Then Exit AutoItWinSetTitle($g_szVersion)

#include <IE.au3>
HotKeySet ("{F7}", "EMSWrite")
HotKeySet ("{ESC}", "EMSExit")
;;;;;;;;;;
While 1
Sleep(1000)
WEnd
;;;;;;;;;;
Func EMSExit()
Exit
EndFunc
Func IfExsists()
If WinExists("HP-JPMC Portal - Microsoft Internet Explorer") = 1 Then
Call ("EMSWrite")
Endif
EndFunc
Func EMSWrite()
$EMShandle = ControlGetHandle("HP-JPMC Portal", "", "")$oIE = _IEAttach($EMShandle, "HWND")$oForm = _IEFormGetObjByName ($oIE, "Form1")$oText = _IEFormElementGetObjByName ($oForm, "_ctl1:txtReqName")$oUID = _IEFormElementGetValue ($oText) ;;;;;;;;;; If FileExists(@ScriptDir&"\Inifiles\"&$oUID&".ini") = 0 Then
TrayTip("", "No UID file found", 3, 1)
Endif
;;;;;;;;;;
$oReqFULLName = _IEFormElementGetObjByName ($oForm, "_ctl1:txtReqName")
$oReqPhone = _IEFormElementGetObjByName ($oForm, "_ctl1:txtReqPhone")
$oCostCenter = _IEFormElementGetObjByName ($oForm, "_ctl1:txtCostCenter")
$oFloor = _IEFormElementGetObjByName ($oForm, "_ctl1:txtFloor")
$oSite = _IEFormElementGetObjByName ($oForm, "_ctl1:lstSites")
$oState = _IEFormElementGetObjByName ($oForm, "_ctl1:lstState")
;;;;;;;;;;
$ReqFname = IniRead(@ScriptDir&"\Inifiles\"&$oUID&".ini","EMS_Info","ReqFname","")
$ReqLname = IniRead(@ScriptDir&"\Inifiles\"&$oUID&".ini","EMS_Info","ReqLname","")
$ReqPhone = IniRead(@ScriptDir&"\Inifiles\"&$oUID&".ini","EMS_Info","ReqPhone","")
$CostCenter = IniRead(@ScriptDir&"\Inifiles\"&$oUID&".ini","EMS_Info","CostCenter","")
$Floor = IniRead(@ScriptDir&"\Inifiles\"&$oUID&".ini","EMS_Info","Floor","")
$Site = IniRead(@ScriptDir&"\Inifiles\"&$oUID&".ini","EMS_Info","Site","")
$State = IniRead(@ScriptDir&"\Inifiles\"&$oUID&".ini","EMS_Info","State","")
;;;;;;;;;;
;MsgBox (0,"", $Site) For testing ini file _IEFormElementSetValue ($oReqFULLName, $ReqFname&" "&$ReqLname);BUG, need to get rid of spacing
_IEFormElementSetValue ($oReqPhone,$ReqPhone)
_IEFormElementSetValue ($oCostCenter,$CostCenter)
_IEFormElementSetValue ($oFloor,$Floor)
_IEFormElementOptionselect ($oState,$State)
;_IEFormElementOptionselect ($oSite,62, 1, "byIndex");WORKS ;_IEFormElementOptionselect ($oSite, "174", 1);WORKS
;_IEFormElementOptionselect ($oSite, '""174"">NYM234(270 Park Avenue)',1,"byText");DOESN'T WORK _IEFormElementOptionselect ($oSite, "sdfs",1,"byText");DOESN'T WORK
EndFunc

I put in the last IE line with an erroneous string and I still dont' get any errors. This is what Scite it outputting....

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /beta /ErrorStdOut /in "C:\Documents and Settings\xxxxxxx\Desktop\EMSini\EMSini.au3" /autoit3dir "C:\Program Files\AutoIt3\beta" /UserParams

+> Starting AutoIt3Wrapper v.1.7.3

>Running AU3Check (1.54.4.0) params: from:C:\Program Files\AutoIt3\beta

+>AU3Check ended.rc:0

>Running:(3.2.1.12):C:\Program Files\AutoIt3\beta\autoit3.exe "C:\Documents and Settings\xxxxxx\Desktop\EMSini\EMSini.au3"

+>AutoIT3.exe ended.rc:0

>Exit code: 0 Time: 22.178

Edited by someone

While ProcessExists('Andrews bad day.exe')
BlockInput(1)
SoundPlay('Music.wav')
SoundSetWaveVolume('Louder')
WEnd

##### Share on other sites

You should get an IEStatusNoMatch error if it doesn't find the correct selection.

That said, try using partial text to match the selection. I'm not certain what mode IEFormElementSelectOption uses when searching for the text, Dale would know that. Try using

_IEFormElementSelectOption($oSite, "270 Park Avenue", 1, "byText") IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] #### Share this post ##### Link to post ##### Share on other sites You should get an IEStatusNoMatch error if it doesn't find the correct selection. That said, try using partial text to match the selection. I'm not certain what mode IEFormElementSelectOption uses when searching for the text, Dale would know that. Try using _IEFormElementSelectOption($oSite, "270 Park Avenue", 1, "byText")
No that isn't working either... I'm not sure why but I'm not getting any errors. If I screw up the $oSite var I get an error --> IE.au3 Error from function _IEFormElementOptionselect,$_IEStatus_InvalidDataType

That *should* mean its finding the table correctly right?

While ProcessExists('Andrews bad day.exe')
BlockInput(1)
SoundPlay('Music.wav')
SoundSetWaveVolume('Louder')
WEnd

##### Share on other sites

Hmm the same thing doesn't work on the State drop down menu, but again value and index work there.

Could it be the way the website was designed?

While ProcessExists('Andrews bad day.exe')
BlockInput(1)
SoundPlay('Music.wav')
SoundSetWaveVolume('Louder')
WEnd

##### Share on other sites

#16 ·  Posted (edited)

Yeah, if it's not giving you an _IEFormElementGetObjByName error, then you've correctly obtained the box. This is also evident from the fact that you can select it using indexing. You can check @error to make certain. I don't see any other issues at the moment, I'd like to try running your code on the site, is it possible to make a guest account or something? If not, could you provide a reproducer page? Otherwise I'm outta ideas for now...

Edit: Could you focus on the combo boxes and send a string of what you want to click?

Edited by mikehunt114

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]

##### Share on other sites

I'll have to try the focus and sending thing. How would I do that? I thought with IE you had to use the IE.au3 method(which would be _IEFormElementOptionselect).

When I look at the source code, I didn't notice this before, but the way the page is setup is that you click on a state(with NY being the def already selected), and then it refreshes and populates the list of sites. However looking at the source code it only lists the sites of whatever state is selected. If you look at the header for the table(or form of whatever it is), you see

<TD align="right"><span id="_ctl1_lblSite" style="color:Blue;">Site</span></TD>

<TD style="WIDTH: 221px" align="left"><select name="_ctl1:lstSites" onchange="__doPostBack('_ctl1$lstSites','')" language="javascript" id="_ctl1_lstSites" tabindex="4" style="width:208px;"> Does that mean theres a javascript to blame for this? My thinking is that maybe it pulls off a javascript element to populate the list of sites, therefor the name we see isn't the actual name. I don't know javascript so theres a huge chance I'mm way off, but I'd like to hear someone elses opinion. Only other thing is, when I change the o_object from _ctl1_lstSites to _ctl1:lstSites nothing changes. Is that normal? While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd #### Share this post ##### Link to post ##### Share on other sites Can your script correctly choose the State from the box? Try selecting different states and seeing what effect it has on the names in the Site box. A DOM viewer would probably be very useful in this case. IE Dev Toolbar is a good tool to use for lots of this kind of stuff. With this toolbar you can click on an element and it's properties will be displayed. Check this out and see if it helps you discern the source of your problem. As for the focus/send string idea, I meant something like this: Opt("WinTitleMatchMode", 2)$string = "NYM234(270 Park Avenue)"
$oSite.focus ControlSend("Internet Explorer", "", "",$string)

The idea was that it's similar to clicking the box, then starting to type out the address you desire.

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]

##### Share on other sites

#19 ·  Posted (edited)

Post the HTML source again or send it to me via PM along with a summary of what you are trying to do..

Dale

Edited by DaleHohm

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

Automate input type=file (Related)

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble