Code: Select all
div class="sa-form-control sa-form-field" style="padding-bottom: 20px;"><select name="country" class="ui-textfield ui-textfield-system sa-country sa-error-field"><option selected="selected" value="">--Please Select--</option>
<option value="RU">Russian Federation</option>
<option value="US">United States</option>
<option value="ES">Spain</option>
<option value="FR">France</option>
option value="OTHER">Other Country</option>
<option value="">-------- Country & Territories (A-Z) --------</option></select>
<div class="sa-success-icon" style="display: none;"></div><p class="sa-error-tips" style="display: block;">Please select a Country/Region</p></div>
If this is someone else's website there is a high probability that they are using a form
<form>...</form>. If this is the case you would be better making a HTTP GET/POST request instead of using JavaScript to fill the form. This way you can use all your AHK knowledge to make your own GUI and do the rest with HTTP requests.
HTTP requests are a lot more complex though, and you would be best using something like Google chrome to see the headers. Here's an example I used for automating
this council website:
Code: Select all
function getMonthData(callback){
httpPostAsync("https://pawam.gedling.gov.uk/online-applications/monthlyListResults.do?action=firstPage","searchCriteria.parish=&searchCriteria.ward=&month=Nov+16&dateType=DC_Validated&searchType=Application",function(txt){
console.log("Getting 100 results per page...")
httpPostAsync("https://pawam.gedling.gov.uk/online-applications/pagedSearchResults.do","searchCriteria.page=1&action=page&orderBy=DateReceived&orderByDirection=Descending&searchCriteria.resultsPerPage=100",function(txt){
var docx = XMLDOM(txt)
window.docx = docx
var results = docx.getElementsByClassName("searchresult")
window.results = results
console.clear()
console.log("Appending results to array...")
for (var el of results){
var elDescripter = el.getElementsByTagName("a")[0]
var elAddresser = el.getElementsByClassName("address")[0]
var elMetaInfo = el.getElementsByClassName("metaInfo")[0]
//Get info from elements
var sDescription = standardiseText(elDescripter.innerText)
var sURL = elDescripter.attributes[0].value
var sAddress = standardiseText(elAddresser.innerText)
//Parse metadata
var sMetadata = standardiseText(elMetaInfo.innerText)
var RefNum = standardiseText(sMetadata.match(/Ref. No: ([^|]+)/)[1])
var DateReceived = standardiseText(sMetadata.match(/Received: ([^|]+)/)[1])
var DateValid = standardiseText(sMetadata.match(/Validated: ([^|]+)/)[1])
var Status = standardiseText(sMetadata.match(/Status: (.+)/)[1])
window.bigArray.push([sDescription,sAddress,RefNum,DateReceived,DateValid,Status,sURL].join(","))
}
});
});
}
function standardiseText(s){
s=s.replace(/\<.+?\>/g,"") //replace all html tags with blank
s=s.replace(/\s+/g," ") //replace all \s+ with space
return s.trim()
}
function XMLDOM(xml){
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(xml,"text/html")
return xmlDoc
}
function httpPostAsync(url,params,callback){
//Get data by posting a http request
//Example:
// url = "get_data.php";
// params = {lorem:"ipsum",name:"binny"} --> "lorem=ipsum&name=binny";
var http = new XMLHttpRequest();
http.open("POST", url, callback!=undefined); //ask for callback only if defined
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//Below are not required anymore. See: https://stackoverflow.com/questions/7210507/ajax-post-error-refused-to-set-unsafe-header-connection
//http.setRequestHeader("Content-length", params.length);
//http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
if(callback!=undefined) callback(http.responseText);
}
}
http.send(params);
}
There are also http request functions that you can
use directly in AHK, but I have no experience with using it. However I would probably advise it unless you want to get used
to callback hell