Can't click a button within web page, no errors are returning.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jayedeee
Posts: 4
Joined: 10 Jan 2018, 18:31

Can't click a button within web page, no errors are returning.

10 Jan 2018, 18:44

When running I am not getting any error messages

the button I am trying to interact with isn't within any iFrame within the page but there are iFrames.

iWB2 is giving me:

<button title="" class="btn btn-inverse btn-icon" onclick="javascript: assignCSRFToken(); this.form.action='/main/location/hrsx/pinebluff/yard/carSearch';this.form.target='imain';this.form.submit(); return false;" type="submit" target="imain" value="search" <input="">
<i class="icon-search"></i>
</button>



Code: Select all

#singleinstance Force
Obj := ComObjActive("Excel.Application")
Cell := Obj.ActiveCell ; The cell to start at.

wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := True
wb.Navigate("https://ey2.expressyard.com/main/login")
WinMaximize, % "ahk_id " WB.HWND
While wb.readyState!=4 || wb.document.readyState!="complete" || wb.busy
   Sleep 50

;login
;================================================================================

wb.Document.All.cmp.Value := "company"
wb.Document.All.usr.Value := "username"
wb.Document.All.pwd.Value := "password"
wb.Document.All.btn1.click()

While wb.readyState!=4 || wb.document.readyState!="complete" || wb.busy
   Sleep 50

;select Location
;============================================================================================

wb.document.All.location.selectedIndex := 14

While wb.readyState!=4 || wb.document.readyState!="complete" || wb.busy
   Sleep 50

wb.Document.GetElementById("btn1").click()

sleep, 3000

wb.quit()

sleep, 500

;Make new Window Object
;========================================================================================

IEGet(Name="")		;Retrieve pointer to existing IE window/tab
 {
	 IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
		 Name := ( Name="ExpressYard - View Yard - Internet Explorer" ) ? "about:Tabs" 
		 : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
	 For Pwb in ComObjCreate( "Shell.Application" ).Windows
		 If ( Pwb.LocationName = Name ) && InStr( Pwb.FullName, "iexplore.exe" )
			 Return Pwb
 }

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)
      }
   }
}

; Jethrow's updated IEGet
IEGet2(Name="", HwndFilter="") {
	if (Name = "")	;// Get active window name if no parameter
		WinGetTitle, Name, % "ahk_id" HwndFilter:=WinExist("ahk_class IEFrame")
	else if (HwndFilter="A" or HwndFilter="Active")
		WinGet, HwndFilter, ID, ahk_class IEFrame
	Name := (Name="New Tab - Windows Internet Explorer")? "about:Tabs":RegExReplace(Name, " - (Windows|Microsoft) Internet Explorer")
	for wb in ComObjCreate("Shell.Application").Windows
		if wb.LocationName=Name and InStr(wb.FullName, "iexplore.exe")
			if Not HwndFilter or (HwndFilter and wb.hwnd=HwndFilter)
				return wb
}
wb2 := WBGet()
wb2.Visible := True
WinMaximize, % "ahk_id " Wb2.HWND
While wb2.readyState!=4 || wb2.document.readyState!="complete" || wb2.busy
   Sleep 60000

; Use A_Index to calculate the curent cell's offset from the starting cell.
CurrentCell := Cell.Offset(0, 0)

Mark := CurrentCell.Offset(1, 0).Text
RepairDate := CurrentCell.Offset(2, 0).Text
Initial := CurrentCell.Offset(3, 0).Text
Numb := CurrentCell.Offset(4, 0).Text
Loc := CurrentCell.Offset(5, 0).Text
Qty := CurrentCell.Offset(6, 0).Text
CC := CurrentCell.Offset(7, 0).Text
AJC := CurrentCell.Offset(8, 0).Text
AQ := CurrentCell.Offset(9, 0).Text
AUQ := CurrentCell.Offset(10, 0).Text
WM := CurrentCell.Offset(11, 0).Text
RJC := CurrentCell.Offset(12, 0).Text
RQ := CurrentCell.Offset(13, 0).Text
Parts := CurrentCell.Offset(14, 0).Text
Description := CurrentCell.Offset(15, 0).Text
CID := CurrentCell.Offset(16, 0).Text
A_Mo := CurrentCell.Offset(17, 0).Text
A_Yr := CurrentCell.Offset(18, 0).Text
A_Mfr := CurrentCell.Offset(19, 0).Text
A_Class := CurrentCell.Offset(20, 0).Text
A_Scale := CurrentCell.Offset(21, 0).Text
A_Fng := CurrentCell.Offset(22, 0).Text
R_Mo := CurrentCell.Offset(23, 0).Text
R_Yr := CurrentCell.Offset(24, 0).Text
R_Mfr := CurrentCell.Offset(25, 0).Text
R_Class := CurrentCell.Offset(26, 0).Text
R_Scale := CurrentCell.Offset(27, 0).Text
R_Fng := CurrentCell.Offset(28, 0).Text
Labor := CurrentCell.Offset(29, 0).Text

if (CurrentCell.Value = "")
{
	Msgbox, complete
	exitapp
}

else

{
	if (CurrentCell.Value = 1)    ;New Car
	;==========================================================================================
	{
		wb2.Document.All.sCriteria.text := Initial
		wb2.Document.All.sCriteria.text := Numb
		wb2.Document.All.getElementsByClass("btn btn-inverse btn-icon").Item.Click()
	}

	else
	{
		Msgbox, New Line
		exitapp
	}

}


esc::exitapp
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Can't click a button within web page, no errors are returning.

10 Jan 2018, 19:03

Hi jayedeee,
I guess the issue lies in the fact that your somenodelist.item() method lacks its first required parameter - the index of the node in the NodeList object.
Hope this helps.
my scripts
jayedeee
Posts: 4
Joined: 10 Jan 2018, 18:31

Re: Can't click a button within web page, no errors are returning.

10 Jan 2018, 20:44

A_AhkUser wrote:Hi jayedeee,
I guess the issue lies in the fact that your somenodelist.item() method lacks its first required parameter - the index of the node in the NodeList object.
Hope this helps.
Didn't seem to work still.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Can't click a button within web page, no errors are returning.

11 Jan 2018, 18:54

Hi,

First - IMO - you should not use Document.All - it is deprecated; I don't really know for what is stands exactly btw - document.getElementsByTagName("*")?

Use document.getElementById, document.getElementsByClassName, document.getElementsByTagName and/or document.querySelector instead.

For instance, and in order to click the sign-in button:

Code: Select all

wb2.document.getElementsByClassName("btn btn-primary btn-login pull-right")[0].click()
Hope this helps.
my scripts
mmmzq
Posts: 8
Joined: 10 Jan 2018, 00:31

Re: Can't click a button within web page, no errors are returning.

11 Jan 2018, 20:56

Code: Select all

wb2.document.getElementByClassName("btn btn-inverse btn-icon")[0].click()
A number index ([0]) should be append to the getElementByClassName() to indicate to the correct node.
Without this index all you get is a element list object.
jayedeee
Posts: 4
Joined: 10 Jan 2018, 18:31

Re: Can't click a button within web page, no errors are returning.

19 Jan 2018, 17:20

I finally got it to work and here's the code I used but there's an element on the next page I still can't get to.

Code: Select all

#singleinstance Force
Obj := ComObjActive("Excel.Application")
Cell := Obj.ActiveCell ; The cell to start at.

wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := True
wb.Navigate("https://ey2.expressyard.com/main/login")
WinMaximize, % "ahk_id " WB.HWND
While wb.readyState!=4 || wb.document.readyState!="complete" || wb.busy
   Sleep 50

;login
;================================================================================

wb.Document.All.cmp.Value := "company"
wb.Document.All.usr.Value := "username"
wb.Document.All.pwd.Value := "password"
wb.Document.All.btn1.click()

While wb.readyState!=4 || wb.document.readyState!="complete" || wb.busy
   Sleep 50

;select Location
;============================================================================================

wb.document.All.location.selectedIndex := 14

While wb.readyState!=4 || wb.document.readyState!="complete" || wb.busy
   Sleep 50

wb.Document.GetElementById("btn1").click()

sleep, 3000

wb.quit()

sleep, 500

;Make new Window Object
;========================================================================================

IEGet(Name="")		;Retrieve pointer to existing IE window/tab
 {
	 IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
		 Name := ( Name="ExpressYard - View Yard - Internet Explorer" ) ? "about:Tabs" 
		 : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
	 For Pwb in ComObjCreate( "Shell.Application" ).Windows
		 If ( Pwb.LocationName = Name ) && InStr( Pwb.FullName, "iexplore.exe" )
			 Return Pwb
 }

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)
      }
   }
}

; Jethrow's updated IEGet
IEGet2(Name="", HwndFilter="") {
	if (Name = "")	;// Get active window name if no parameter
		WinGetTitle, Name, % "ahk_id" HwndFilter:=WinExist("ahk_class IEFrame")
	else if (HwndFilter="A" or HwndFilter="Active")
		WinGet, HwndFilter, ID, ahk_class IEFrame
	Name := (Name="New Tab - Windows Internet Explorer")? "about:Tabs":RegExReplace(Name, " - (Windows|Microsoft) Internet Explorer")
	for wb in ComObjCreate("Shell.Application").Windows
		if wb.LocationName=Name and InStr(wb.FullName, "iexplore.exe")
			if Not HwndFilter or (HwndFilter and wb.hwnd=HwndFilter)
				return wb
}
wb2 := WBGet()
wb2.Visible := True
WinMaximize, % "ahk_id " Wb2.HWND
While wb2.readyState!=4 || wb2.document.readyState!="complete" || wb2.busy
   Sleep 60000

; Use A_Index to calculate the curent cell's offset from the starting cell.
CurrentCell := Cell.Offset(0, 0)

Mark := % CurrentCell.Offset(0, 1).Text
RepairDate := % CurrentCell.Offset(0, 2).Text
Initial := % CurrentCell.Offset(0, 3).Text
Numb := % CurrentCell.Offset(0, 4).Text
Loc := % CurrentCell.Offset(0, 5).Text
Qty := % CurrentCell.Offset(0, 6).Text
CC := % CurrentCell.Offset(0, 7).Text
AJC := % CurrentCell.Offset(0, 8).Text
AQ := % CurrentCell.Offset(0, 9).Text
AUQ := % CurrentCell.Offset(0, 10).Text
WM := % CurrentCell.Offset(0, 11).Text
RJC := % CurrentCell.Offset(0, 12).Text
RQ := % CurrentCell.Offset(0, 13).Text
Parts := % CurrentCell.Offset(0, 14).Text
Description := % CurrentCell.Offset(0, 15).Text
CID := % CurrentCell.Offset(0, 16).Text
A_Mo := % CurrentCell.Offset(0, 17).Text
A_Yr := % CurrentCell.Offset(0, 18).Text
A_Mfr := % CurrentCell.Offset(0, 19).Text
A_Class := % CurrentCell.Offset(0, 20).Text
A_Scale := % CurrentCell.Offset(0, 21).Text
A_Fng := % CurrentCell.Offset(0, 22).Text
R_Mo := % CurrentCell.Offset(0, 23).Text
R_Yr := % CurrentCell.Offset(0, 24).Text
R_Mfr := % CurrentCell.Offset(0, 25).Text
R_Class := % CurrentCell.Offset(0, 26).Text
R_Scale := % CurrentCell.Offset(0, 27).Text
R_Fng := % CurrentCell.Offset(0, 28).Text
Labor := % CurrentCell.Offset(0, 29).Text
;url1 := "https://ey2.expressyard.com/main/location/hrsx/pinebluff/yard/carSearch?sInitials="
;url2 := "&sNumber="
;url3 := "&sEpisodeNumber=&sInStartDate=&sInEndDate=&sOutStartDate=&sOutEndDate=&sRepairStartDate=&sRepairEndDate=&sCarKindCode=&sBillable="
form := wb2.document.searchform
form2 := wb2.document.parentWindow.frames["imain"]
formInputs := form.getElementsByTagName("input")
formInputs2 := form.getElementsByTagName("button")


if (CurrentCell.Value = "")
{
	Msgbox, complete
	exitapp
}

else

{
	if (CurrentCell.Value = 1)    ;New Car
	;==========================================================================================
	{
	Loop % formInputs.length 
	if (formInputs[A_Index-1].type = "text")
		formInputs[A_Index-1].value := Initial Numb

	Loop % formInputs2.length 
	if (formInputs2[A_Index-1].type = "submit")
		formInputs2[A_Index-1].click()

	While wb2.readyState!=4 || wb2.document.readyState!="complete" || wb2.busy
   	Sleep 50


   	           
	loop, % form2.Length                                    
	{	
		if ( img[(A_index-1)].src = "/main/public/repair-1.0.0/car_info/wrench_invoiced.gif" )
		{
			img[(A_index-1)].click()
			break ; break loop
		}
	} 


 	}
	else
	{
		Msgbox, New Line
		exitapp
	}

}


esc::exitapp
Here's the code on the page.

https://imgur.com/a/CBUJS

Please give me any ideas you might have.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 262 guests