how to get an element withou id

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Nizar
Posts: 1
Joined: 23 May 2017, 08:43

how to get an element withou id

23 May 2017, 09:12

<input name="password" tabindex="2" type="password" size="19" maxlength="50" value="">
Iam new to autohotkey ihave made this script whish work for the username (because it owns an id) but won't work for the passord field i know it's something about an array and i must too choose the desired one

Code: Select all

My_User_Name := "*****" 
My_Pass_Word := "****"
web_browser := ComObjCreate("InternetExplorer.Application")
web_browser.Visible := true
web_browser.Navigate("http://www.fieldclimate.com/")
while web_browser.busy ; a while loop is a way to keep the script testing an IF like expression 
sleep 100 ; IF web_browser.busy is true then sleep 100 milliseconds
sleep 1000 ; extra time
username_input := web_browser.document.getElementById("id_username")
username_input.value := My_User_Name
password_input := web_browser.document.getElementByName("password").getElementByTagName("INPUT")[7]																		
password_input.value := My_Pass_Word
MsgBox, That's what iam talking about
web_browser.document.getElementsByTagName("A")[5].click() ;IE4.document.getElementsByClassName("submitBtn")[0].click()
web_browser.document.getElementsById("export_excel").click()
Return
Last edited by tank on 25 May 2017, 07:37, edited 1 time in total.
User avatar
jmeneses
Posts: 524
Joined: 28 Oct 2014, 11:09
Location: Catalan Republic

Re: how to get an element withou id

25 May 2017, 07:23

Hi Nizar and welcome to AHK, try this

Code: Select all

My_User_Name := "MyName" 
My_Pass_Word := "****"
oUrl := "http://www.fieldclimate.com/"

 If WinExist("ahk_class IEFrame") {
    WinActivate ahk_class IEFrame
    WinGetText, oText, A
    If (Instr(oText,RegExReplace(oUrl,"(\?.+)"))) {
        oIE := IEGet()
    }
 }

 If (!IsObject(oIE))   {
    oIE := ComObjCreate( "InternetExplorer.Application" )
 }

 oIE.visible := true
 oIE.Navigate(oUrl)
 For oIE in ComObjCreate("Shell.Application").Windows
  If InStr(oIE.LocationURL, oUrl)
     break  
 
 load_complete(oIE)
 WinActivate % "ahk_id " oIE.HWND
 WinMaximize % "ahk_id " oIE.HWND
 
 oIE.document.getElementById("id_username").Focus()
 oIE.document.getElementById("id_username").value := My_User_Name       
 oIE.document.getelementsbytagname("INPUT")[7].Focus()
 oIE.document.getelementsbytagname("INPUT")[7].value :=My_Pass_Word
 oIE.document.formLogin.submit()
 ;web_browser.document.getElementsById("export_excel").click() 
 ExitApp
;********************************************************
 load_complete(oIE){   
 If (!IsObject(oIE))    {
    Msgbox 0x40000, % A_ThisFunc ,  "ERROR objecte oIE!!" 
    Return False
 }
 Loop
  Sleep % pSleep
 Until (!oIE.busy)
 
 Loop {
   Sleep,100
 } Until (oIE.Document.Readystate = "Complete")

 Return True
 }

 IEGet(name=""){
 for WB in ComObjCreate("Shell.Application").Windows       {
    If (wb.LocationName ~= Name) and InStr(wb.FullName, "iexplore.exe")
       Return wb
    }
 }
Look this WinSpy - Window Information Tool or this iWB2_Learner
Donec Perficiam
User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: how to get an element withou id

25 May 2017, 08:00

Only getElementById is singular getElementByName and getElementByTagName should be getElementsByName and getElementsByTagName

Code: Select all

password_input := web_browser.document.getElementsByName("password")[0].value
Please excuse my spelling I am dyslexic.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 330 guests