COM interacting with Java Script button on website

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Guiltyspark91
Posts: 8
Joined: 17 Jun 2016, 15:47

COM interacting with Java Script button on website

28 Jun 2016, 11:41

Hello All.
I have been reading posts on here regarding COM and interacting with Internet explorer. Really enjoying this community. I am very new to the object oriented side of AHK but have some experience with automation through AHK.
I am working on a project where I am logging into a sales site and going into a queue where I see quotes. There is a JS refresh button within the page that allows me to refresh the data without refreshing the entire page. I would like to click this at a short interval, wait for the page to load and then Read/ Scrape specific data and apply logic to it in order to alert me when specific types of quotes have been in there too long or if there are more than one. For now I am just working on the refreshing portion. I am having problems finding and clicking this refresh button and was wondering if you guys could help me out. Also the majority of this script is taken from a post from JP Chartrand with help from the user Jackie Sztuk _Blackholyman So credit to them.
This is what I have so far. Note I have left out the website and my username password just for privacy reasons.

Code: Select all

web_browser := ComObjCreate("InternetExplorer.Application")
web_browser.Visible := true
web_browser.Navigate("https://login.com/")
while web_browser.busy
sleep 1000
username_input := web_browser.document.getElementById("username")
username_input.value := My_User_Name
password_input := web_browser.document.getElementById("password")
password_input.value := My_Pass_Word
web_browser.document.getElementById("Login").click()
sleep 5000
inner_links := web_browser.document.getElementByClassName("listButtons")
Loop % inner_links.length
{
    If (inner_links[A_index-1].title = "Refresh")
    {
        inner_links[A_index-1].click()
        Break
    }
}
The button I am trying to click and wait for a load on the page is

Code: Select all

<input type="button" id="00BU0000003uTEV_refresh" src="s.gif" href="javascript:void(0)" onclick="javascript:ListViewport.instances['00BU0000003uTEV'].refreshList()" class="btn refreshListButton" title="Refresh">
Also I currently do not have a good loop to keep it running. I was wonding if I could use a key input like in normal ahk scripts like While stop = 0 (hit refresh button) and then have 1:: stop = 1, 2:: stop =0. Does that work with this object oriented side of AHK.
Thanks in advance.
User avatar
sinkfaze
Posts: 616
Joined: 01 Oct 2013, 08:01

Re: COM interacting with Java Script button on website

28 Jun 2016, 12:06

Your button has an ID so you can use that to attach to it directly. The click is likely not firing the associated onclick javaScript event, so you'll have to fire that manually:

Code: Select all

refresh :=	web_browser.document.all["00BU0000003uTEV_refresh"]
 , refresh.click()
 , refresh.fireEvent("onclick")
Guiltyspark91
Posts: 8
Joined: 17 Jun 2016, 15:47

Re: COM interacting with Java Script button on website

28 Jun 2016, 12:28

Thank you so much for getting back to me so quickly. I will have to read up on the .fireEvent as I have not seen that before.
Currently I am now using an updated version but have yet to get it to work any idea what im doing wrong?

Code: Select all

web_browser := ComObjCreate("InternetExplorer.Application")
web_browser.Visible := true
web_browser.Navigate("https://login.com/")

while web_browser.busy
sleep 100
sleep 1000
username_input := web_browser.document.getElementById("username")
username_input.value := My_User_Name
password_input := web_browser.document.getElementById("password")
password_input.value := My_Pass_Word
web_browser.document.getElementById("Login").click()
sleep 5000

refresh :=	web_browser.document.all["00BU0000003uTEV_refresh"]
Loop,1000
{
refresh.click()
refresh.fireEvent("onclick")
}
okl

Re: COM interacting with Java Script button on website

06 Nov 2016, 00:31

thank you Sinkfaze, the code does work for a javascript button on a webpage that i am trying to automate as well... had trouble using other codes written on this site for clicking until i found your code.

thanks!!!
okl

Re: COM interacting with Java Script button on website

07 Nov 2016, 07:56

i have a problem... once the code is entered, it does "click" on the said button, but after that- an OK button pops up and the AHK script stops running.

Code: Select all

wb.document.all["ctl00_ContentPlaceHolder1_WucCRC1_WucCOManualAssignment1_btnAssign"].click()

only after I manually click on the pop up OK button does the script continue running.

i thought that line of code was trapping things, so I've tried putting in sleep, break, return... but nothing seems to work, the AHK script just stops running after the "click" is made and only resumes after I click on the pop up OK

any idea what's going on and how to resolve it? it's been bugging me for a day and I'm running out of ideas.


the strangest thing is that when I use "imagesearch" to click on the Assign button, it doesn't affect the script and will continue to automatically click on the ok button as scripted. I have had to switch to using the above method instead of imagesearch because for some reason that I have no idea, imagesearch doesn't work very consistently to detect this Assign button.

help!!
okl

Re: COM interacting with Java Script button on website

07 Nov 2016, 08:01

missed out the element to the assign button earlier

Code: Select all


<INPUT onclick='return confirmAssign();WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$WucCRC1$WucCOManualAssignment1$btnAssign", "", true, "", "", false, false))' id=ctl00_ContentPlaceHolder1_WucCRC1_WucCOManualAssignment1_btnAssign type=submit value=Assign name=ctl00$ContentPlaceHolder1$WucCRC1$WucCOManualAssignment1$btnAssign>

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 322 guests