Help Obtaining IE Values and Writing Values In To Them

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
smogmanus
Posts: 45
Joined: 27 Jul 2015, 12:44

Help Obtaining IE Values and Writing Values In To Them

28 Oct 2019, 16:32

Hello,

I am trying to automate obtaining information from our orders page. I want to try to get all of the information from the APP and I can get some of it.

These work.

Code: Select all

woout:=pwb.document.getElementByID("arid_WIN_0_600200016").Value ; Work Order Number

    ;~ MsgBox, %  woout 

    srwout:=pwb.document.getElementByID("arid_WIN_0_536870918").Value ; Service Request Number 
      ;~ MsgBox , % srwout
What doesn't work is is being able to have AHK go to the inter text "Hours of Operation" if it clicks on there then I can jump to
arid_WIN_0_600300002 to insert the value.

Then I would need AHK to jump to the Next Field Serial No.
If you look at the jpg the fields are there but I don't know how to get the information. In the IWBlearner You will note the values in the field values.
I just don't know how to get them back or paste information in properly.

Any help would be greatly appreciated.
Attachments
ahkcom.jpg
ahkcom.jpg (242.1 KiB) Viewed 3729 times
adrian_9832
Posts: 26
Joined: 23 Dec 2018, 00:40

Re: Help Obtaining IE Values and Writing Values In To Them

28 Oct 2019, 21:14

i suggest use selenium to retrieve data
StefVelikov
Posts: 39
Joined: 15 Sep 2019, 09:20

Re: Help Obtaining IE Values and Writing Values In To Them

29 Oct 2019, 03:34

Hey man,
To set a blue to a field use same function as you have used but this way ->

Code: Select all

Pwb.document.getElementbyId("the I'd"). innerTEXT:= "the value you need" 
If the field don't have ID's , you can use get by tag name or class name but you have to also specify which one it is because it takes the fields as arrays ( have in mind they are 0-index based which means the first array will be 0, second 1 and so on)

If you don't plan to automate chrome or browser different than IE, I do not recommend using Selenium.

COM is perfect for IE and in my opinion not hard to get it how it works!
smogmanus
Posts: 45
Joined: 27 Jul 2015, 12:44

Re: Help Obtaining IE Values and Writing Values In To Them

31 Oct 2019, 23:34

Thank you for your replies I will checkout Selenium for sure. I am not a very good code writer. I did figure out how to get the information I needed now I need to figure out how to populate the fields after I get all of the information for the router. How do I paste in pertinent back in to the order form. As you can see from this code I've recreated I can get the data in but who to I paste it back into the IDs on the page. This is the code I have so far.

Code: Select all

 :o:wodata.::
;comment get work order data from IE.  It does work.
;~ SoundSet, 0
;~ FileDelete %A_scriptdir%\ordersave.txt
;~ Clipboardold=%Clipboard%
Clipboard = 
gosub clearvars  
SetKeyDelay, 30, 30
Gui, +AlwaysOnTop
winset, AlwaysOnTop, On  


;var:=pwb.LocationURL ;grab current url

;msgbox,, page url, % var 



{
    pwb := WBGet()
    
    woout:=pwb.document.getElementByID("arid_WIN_0_600200016").Value ; Work Order Number

    ;~ MsgBox, %  woout 

    srwout:=pwb.document.getElementByID("arid_WIN_0_536870918").Value ; Service Request Number 
      ;~ MsgBox , % srwout
      
      
    fnout:=pwb.document.getElementByID("arid_WIN_0_600200003").Value ;Unique ID
    
    ;~ MsgBox, % fnout
    
    lnout:=pwb.document.getElementByID("arid_WIN_0_600200006").Value ;Unique ID
    ;~ Msgbox, % lnout
    
    phoneout:=pwb.document.getElementByID("arid_WIN_0_600200004").Value ;Unique ID
    ;~ Msgbox, % phoneout
    
    
    email:=pwb.document.getElementByID("arid_WIN_0_600200640").Value ;Unique ID
    
    ;~ Msgbox, % email
    
    
    vfname:=pwb.document.getElementByID("arid_WIN_0_600200239").Value ;Unique ID
    
    ;~ Msgbox, % vfname
    
    vlname:=pwb.document.getElementByID("arid_WIN_0_600200240").Value ;Unique ID
    
    ;~ Msgbox, % vlname
    
    
    vphone:=pwb.document.getElementByID("arid_WIN_0_600200241").Value ;Unique ID
    
    ;~ Msgbox, % vphone
    
    
    vemail:=pwb.document.getElementByID("arid_WIN_0_600200342").Value ;Unique ID
    
    ;~ Msgbox, % vemail
    

    
    wocomout:=pwb.document.getElementByID("arid_WIN_0_600200720").Value ;Unique ID
;~ MsgBox %wocomout%
Clipboard = %wocomout%
ClipWait, 2
uNames := "Telework request:,NOTE:,user requires Finesse and mobility extension as they will be answering calls at home and in-office,DHS,DHS division name:*,where will the contact center agent log in to Finesse to take calls from: Home address,  HCEO,DHS Telework request,DHS division name:,division name:,DSD,Create.*, FinDept*,Home address:,Work phone number:,Internet service provider,MNIT ticket WO#: ,If yes, does the Teleworker use Calabrio to monitor and record calls:"


;~ "Teleworker ,NOTE:,user requires Finesse and mobility extension as they will be answering calls at home and in-office,DHS division name: HCEO,DHS Telework request,DHS division name: DSD,Create.*,Home address:,o	Home User C.*,If.*,o	Telework User instructions for successful set up,MNIT ticket WO#:,o	SRW#*,o	WO.*,If Teleworker.*,o	911.*,Complete item*,o	User Res.*,Complete items*,o	Teleworker Name,o	Teleworker Division,Complete.*,o	911 Testing.*,s listed in the detail., #,Work phone number:,Internet service provider:,Internet speed:,Work phone number:,Call Center,DHS division name: Member and Provider Services, Agent:,DHS,.*: Appeals,&,division name.*,CVO Project.  Replace the CVO router for this site as a part of the CVO upgrade project,&,<,>,o	Telework User instructions for successful,Supervisor.* " 

    sleep 500
        Loop, Parse, uNames, `,
        clipboard := RegexReplace(clipboard, a_loopfield)
        send {tab}
    ;send  woinfo.ini   {enter 
    StringReplace, clipboard, clipboard, *, , All
    ;~ MsgBox %clipboard%
    sleep 500
    ;~ send ^v

    wocomout = %clipboard% 
    ;~ MsgBox  %wocomout%
    ;~ IfExist, %A_scriptdir%\ordersave.txt
    ;~ {
       ;~ FileDelete %A_scriptdir%\ordersave.txt
    ;~ }
    ;~ else
        
run, %nppp% %A_scriptdir%\ordersave.txt
sleep 5000
send ^a
send {delete}
#WinActivateForce, ordersave.txt Notepad++ ahk_class Notepad++ ahk_exe notepad++.exe
send ^v
send ^v

;~ MsgBox, % srwout

    InputBox, callagent,  Is This User A Call Agent,Yes or No,,,,2235,0,,,Yes  
       
    ;~ MsgBox %callagent%

    
    InputBox, rodout,  Enter DHS ROD Number,ROD #,,,,2235,0,,,NA 
       
    ;~ MsgBox %rodout%
        InputBox, devout,  Enter Device Name ,Devname,,,,2235,0,,,1111
    InputBox, serout,  Enter Serial Number,Serial#,,,,2235,0,,,1111
    
    
    InputBox, assout,  Enter Asset Number,Asset#,,,,2235,0,,,1111
    ;~ MsgBox     %assout%


InputBox, lbout,  Enter Loopback,Loopback,,,,2235,0,,,1111
    ;~ MsgBox %lbout%
    
    
  
InputBox, dnout,  Enter Data Network,Data Network,,,,2235,0,,,1111

    
InputBox, vnout,  Enter Voice Network,Voice Network,,,,2235,0,,,1111

Inputbox trunkout, Enter Provider and Speed, Details,,,,2235,0,,1111

strout:=pwb.document.getElementByID("arid_WIN_0_600100063").Value ;Unique ID


if InStr(strout, "540 CEDAR ST") or instr(strout, "345 PLATO BLVD ") or instr(strout, "444 LAFAYETTE")  
{
 
    ;~ ;InputBox, OutputVar [, Title, Prompt, HIDE, Width, Height, X, Y, Font, Timeout, Default]
    ;~ InputBox, OutputVar, Last Name, What Is The Last Name,,,,2235,0,,,Default
    InputBox strout, Enter The Real Street Address, Street Address,,,,2235,0,,1111
    inputbox ctout, Enter City, Enter City,,,,2235,0,,1111
    inputbox state, Enter State, Enter State,,,,2235,0,,1111
    inputbox  zipout, Enter Zip Code,,,,2235,0,,,1111
    
    addout= %strout%`,  %ctout%,` %state% %zipout%
}

else
{

state:=pwb.document.getElementByID("arid_WIN_0_600100057").Value ;Unique ID

MsgBox, % state

zipout:=pwb.document.getElementByID("arid_WIN_0_600100068").Value ;Unique ID

MsgBox, % zipout

}

    ClipWait, 1
    clipboard := RegexReplace(Clipboard, "\s*(\n|\r\n)", A_Space)
sleep 3000
MsgBox click on notepad
gosub key111
    send %devout%=%lbout%|%serout%|%assout%|%woout%|%srwout%|%rodout%|%dnout%|%vnout%|%trunkout%|%strout%{space}%ctout%{space}%state%{space}%zipout%|%strout%|%ctout%|%state%|%zipout%|%fnout%|%lnout%|%phoneout%|%callagent%|%email%|%vfname%|%vlname%||%vphone%|%vemail%|%A_DDD%, %A_MMM% %A_DD%, %A_YYYY%
   FileAppend,  %devout%=%lbout%|%serout%|%assout%|%woout%|%srwout%|%rodout%|%dnout%|%vnout%|%trunkout%|%strout%{space}%ctout%{space}%state%{space}%zipout%|%strout%|%ctout%|%state%|%zipout%|%fnout%|%lnout%|%phoneout%|%callagent%|%email%|%vfname%|%vlname%||%vphone%|%vemail%|%A_DDD%, %A_MMM% %A_DD%, %A_YYYY%, %A_scriptdir%\ordersave.txt
   ;~ FileAppend, %devout%=%lbout%|%serout%|%assout%|%woout%|%srwout%|%rodout%|%dnout%|%vnout%|%trunkout%|%addout%|%strout%|%ctout%|%state%|%zipout%|%fnout%|%lnout%|%phoneout%|%callagent%|%wocomout%, %A_scriptdir%\ordersave.txt
;~ FileAppend,  %zipout%`n, %A_scriptdir%\ordersave.txt
    ;~ run, notepad++.exe %A_scriptdir%\ordersave.txt
winset, AlwaysOnTop, Off
}
return
[Mod edit: [code][/code] tags added]

How do I put the information back into the web page?
Any help would be greatly appreciated.
Attachments
bmc-order-form.jpg
bmc-order-form.jpg (106.35 KiB) Viewed 3625 times
StefVelikov
Posts: 39
Joined: 15 Sep 2019, 09:20

Re: Help Obtaining IE Values and Writing Values In To Them

01 Nov 2019, 01:57

Hi, glad your having progress with the script.

The way to add the values back in the page is similar to the one you get them with. The command is the following:

Code: Select all

pwb.document.getElementById("arid_WIN_0_600200342").value:= "here put the value or variable" ; just an example
NB! Have in mind that sometimes using .Value may not do the job, if this is the case instead of it, use .InnerText:= the value/variable you need to be in that field.

You can also use getElementsByClassName, getElementsByTagName but using the Id is the best and most reliable option.
StefVelikov
Posts: 39
Joined: 15 Sep 2019, 09:20

Re: Help Obtaining IE Values and Writing Values In To Them

01 Nov 2019, 02:00

Also, if you would like to click a button you can use:

Code: Select all

pwb.document.getElementById("Id of the button").Click()
Good luck, ask if you have issues or question. Glad if i'm helping :)
smogmanus
Posts: 45
Joined: 27 Jul 2015, 12:44

Re: Help Obtaining IE Values and Writing Values In To Them

01 Nov 2019, 07:58

Thank you for your quick reply.

Is there any way to put a variable in the value?

pwb.document.getElementById("arid_WIN_0_600200342").value:= "here put the value or variable" ; just an example
%serialnumber%
or do I recreate the line with the value between the quotes

Something like

send pwb.document.getElementById("arid_WIN_0_600200342").value:= "%serialnumber%" ; just an example

This worked in my editor now I need to test.
serialnumber =
serialnumber = "bradtest"

send pwb.document.getElementById("arid_WIN_0_600200342").value:= %serialnumber% ; just an example

pwb.document.getElementById("arid_WIN_0_600200342").value:= "bradtest"
smogmanus
Posts: 45
Joined: 27 Jul 2015, 12:44

Re: Help Obtaining IE Values and Writing Values In To Them

01 Nov 2019, 08:42

Great news I am now able to populate these fields although I don't have a smooth way to update the pwb line yet. When I populate the fields and I hit update nothing happens.

Code: Select all

pwb := WBGet()
 pwb.document.getElementById("arid_WIN_0_600300005").value:= "bradtest"
pwb.document.getElementById("arid_WIN_0_600300002").value:= "bradtest"

;~ pwb.document.getElementById("arid_WIN_0_600300002").value:= "bradtest"

;************Pointer to Open IE Window******************
WBGet(WinTitle="ahk_class IEFrame", Svr#=1) {               ;// based on ComObjQuery docs
   static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
        , IID := "{0002DF05-0000-0000-C000-000000000046}"   ;// IID_IWebBrowserApp
;//     , IID := "{332C4427-26CB-11D0-B483-00C04FD90119}"   ;// IID_IHTMLWindow2
   SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%

   if (ErrorLevel != "FAIL") {
      lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
      if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
         DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
         return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
      }
   }
}pwb.document.getElementById("arid_WIN_0_600200342").value:= "bradtest"
[Mod edit: [code][/code] tags added]
Attachments
bmc-order-form3.jpg
bmc-order-form3.jpg (115.07 KiB) Viewed 3532 times
StefVelikov
Posts: 39
Joined: 15 Sep 2019, 09:20

Re: Help Obtaining IE Values and Writing Values In To Them

01 Nov 2019, 11:07

To use variable, don't put percentage s nor " "

Pwb.document.getelementbyid("Id").InnerTEXT:=variable

Note to use .InnerTEXT rather than .Value !!!
smogmanus
Posts: 45
Joined: 27 Jul 2015, 12:44

Re: Help Obtaining IE Values and Writing Values In To Them

02 Nov 2019, 08:33

Thank you very much for the information.

Can you tell me where I can find a list of pwb. commands.
Right now I am am pecking around with no real documentation on how and why to use COM commands.

Any help would be greatly appreciated.
Brad
StefVelikov
Posts: 39
Joined: 15 Sep 2019, 09:20

Re: Help Obtaining IE Values and Writing Values In To Them

02 Nov 2019, 11:58

What got me into Web Scraping was Joe Glines, take a look at this website, https://the-automator.com/ , the guy is amazing!!
gregster
Posts: 9113
Joined: 30 Sep 2013, 06:48

Re: Help Obtaining IE Values and Writing Values In To Them

02 Nov 2019, 15:46

smogmanus1 wrote:
02 Nov 2019, 08:33
Can you tell me where I can find a list of pwb. commands.
Right now I am am pecking around with no real documentation on how and why to use COM commands.
pwb is just a random object name for an IE COM object that you created in your code. Internet Explorer is a Microsoft product, so the general documentation for IE's COM interface can be found at Microsoft: https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa752084(v%3Dvs.85)

The interface can be used with most programming languages, but of course AHK-specific examples can be found mainly on the forum here - and of course on Joe Glines' excellent website, like mentioned above. But if you are looking for a complete list of all IE COM methods, propperties and events, then you should look at the MS website.
smogmanus
Posts: 45
Joined: 27 Jul 2015, 12:44

Re: Help Obtaining IE Values and Writing Values In To Them

06 Nov 2019, 18:51

Hello I've been trying to write a variable to IE using com.

This works
pwb.document.getElementByID("arid_WIN_0_600300002").Value :="Brad Static Between Quotes" ;Unique ID-with dashes

However I need to be able to paste a variable in
devout := "bradtest"

How do I paste there variable %devout% into the page instead of a static paste?

I know these don't work.
pwb.document.getElementByID("arid_WIN_0_600300002").value = %devout%
pwb.document.getElementByID("arid_WIN_0_600300002") := %devout%

Or who do I focus on the field an put in a value any help would be greatly appreciated.
gregster
Posts: 9113
Joined: 30 Sep 2013, 06:48

Re: Help Obtaining IE Values and Writing Values In To Them

07 Nov 2019, 06:25

In expressions (for example, assignments with :=), you don't use %s around variables to get its contents. Try

Code: Select all

devout := "bradtest"
pwb.document.getElementByID("arid_WIN_0_600300002").Value := devout
smogmanus
Posts: 45
Joined: 27 Jul 2015, 12:44

Re: Help Obtaining IE Values and Writing Values In To Them

07 Nov 2019, 10:04

Gregster,

I thought I tried it this way but I didn't.

I worked like a charm. Thank you so much for solving this issue for me.

I will continue on with my real data hopefully I can get it to work.

Thanks Again

Brad
smogmanus
Posts: 45
Joined: 27 Jul 2015, 12:44

Re: Help Obtaining IE Values and Writing Values In To Them

07 Nov 2019, 10:16

Can I ask for other help in this?

After I put the data in the field and manually click update row nothing happens. I have to get to work I will finish this note when I get there.

Thank you so much for your help.

Brad
smogmanus
Posts: 45
Joined: 27 Jul 2015, 12:44

Re: Help Obtaining IE Values and Writing Values In To Them

24 Dec 2019, 13:11

I did get this to work. It is certainly not as sophisticated as folks like Joe Glines or Jackie could write but is works.

Code: Select all

;Written By:  Your Name   
::bmcdev::
;~ InputBox, model, Enter Model Number, Number
gosub devload

SetKeyDelay ,50, 50
WinActivate, https cosweb.mnit.state.mn.us /?cacheid=b81be5be&format=html  Broken Link for safety - Update Work Order Detail - Internet Explorer ahk_class IEFrame ahk_exe iexplore.exe
;~ MsgBox,4096, Click In Vendor Comments, Click In Vendor Comments
  pwb := ComObjCreate("InternetExplorer.Application")
  pwb := WBGet()
  WinActivate, https cosweb.mnit.state.mn.us /?cacheid=b81be5be&format=html  Broken Link for safety - Update Work Order Detail - Internet Explorer ahk_class IEFrame ahk_exe iexplore.exe
pwb.document.getelementbyID("arid_WIN_0_600300005").focus()      ; device name
sleep 500
send ^a{delete}
sleep 500
send %devout%
sleep 500
gosub clearvalue
;~ pwb.document.getelementbyID("arid_WIN_0_600300002").focus()  ;Enter Value Field
;~ send ^a{delete}
;~ MsgBox, 4096, Click on Hours, Click on Hours
pwb.document.all.tags("NOBR") [13].click()  ; hours of operation
gosub clearvalue
sleep 250
pwb.document.getelementbyID("arid_WIN_0_600300002").focus()  ;Enter Value Field
send Mon-Fri 0800-1700
sleep 250 
gosub savevalue
sleep 250
pwb.document.all.tags("NOBR") [17].click()  ; serial number field
gosub clearvalue
sleep 250
send %serout%
gosub savevalue
pwb.document.all.tags("NOBR") [21].click()  ; asset number field
gosub clearvalue
send %assout%
gosub savevalue
pwb.document.all.tags("NOBR") [25].click()  ;  model number field
gosub clearvalue
send %modelout%
gosub savevalue
pwb.document.all.tags("NOBR") [29].click()  ;  Manufacturer field
gosub clearvalue
send Cisco
gosub savevalue
pwb.document.all.tags("NOBR") [33].click()  ;  maintenance  field
gosub savevalue
pwb.document.all.tags("NOBR") [37].click()  ;  device field
gosub savevalue
pwb.document.all.tags("NOBR") [41].click()  ;  owner field
gosub clearvalue
send OET Owned/Managed
gosub savevalue

return


savevalue:
pwb.document.all.tags("DIV") [80].click()  ; this clicks update row
sleep 250
return

clearvalue:
pwb.document.getelementbyID("arid_WIN_0_600300002").focus()  ;Enter Value Field
;~ sleep 500
send ^a{delete}
sleep 500
return
smogmanus
Posts: 45
Joined: 27 Jul 2015, 12:44

Re: Help Obtaining IE Values and Writing Values In To Them

18 Feb 2020, 00:33

Thank you for your help.

I am now trying to fill in the value that changes.

Something like this. Is there a way to get the %devname% to fill in another value

devname = Braduvb
pwb := WBGet()
pwb.document.getElementbyID("name").value = %devname%

For some reason I cannot get around the hard " quotes " to put in a value.
smogmanus
Posts: 45
Joined: 27 Jul 2015, 12:44

Re: Help Obtaining IE Values and Writing Values In To Them

18 Feb 2020, 09:17

Thank you your reply worked perfectly.

Now I am running into a randomized seral and asset number.
Each field is serialized to I want to just have it focus on SERIALNUMBER. Is there a way to hone in on just the work SERIALNUMBER instead of <input name="SERIALNUMBER1582031392059"
<input name="SERIALNUMBER1582031392059" class="formInput ng-pristine ng-valid ng-empty ng-touched" id="SERIALNUMBER1582031392059" type="TEXT" ng-model="variableCtrl.data['@attributes'].value" ng-change="selectInputValues();">

I don't know where to go from here.
mevo-serial-asset-mevo.jpg
mevo-serial-asset-mevo.jpg (60.31 KiB) Viewed 2229 times
pwb := WBGet()


MsgBox % pwb.Document.getElementsbyClassName.
smogmanus
Posts: 45
Joined: 27 Jul 2015, 12:44

Re: Help Obtaining IE Values and Writing Values In To Them

18 Feb 2020, 09:53

I just want the words SERIALNUMBER AND ASSETNUMBER. The numbers after these two words randomize the serial numbers in their database. I need just the two words and put in the correct information.
Any help would be greatly appreciated.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 347 guests