Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with ActiveXObject Microsoft.XMLHTTP

Status
Not open for further replies.

suddenzero

Programmer
Feb 1, 2010
2
0
0
US
Hello Everyone Smarter Than Me!

Before I get to the question first a little History on what I am working with. I am a Software Engineer currently working under a contract in a highly customized environment. The IDE that I am using (Not by my choice as I am a Java developer by Trade) uses a "JavaScript Runtime Environment" to treat JavaScript as a complied language. Needless to say this is a little odd and it was created because my employer had trouble finding enough developers that know other languages (This also seems odd) but there always seemed to be a ton of JavaScript people around.

Anyway now to the question. The code I am writing is product testing automation code that is going to save testing dollars eventually. Initially the testing was done by a team of testers whom would log into a website, run some tests by interacting with the website, and then get the results from the tests via the product that they are testing.

My code will do all the interaction with the device and the website and then compile all the results in an Ms. Excell spreadsheet for viewing. The problem is that my employer doesn't own the website that the testing is done from and there has been some changes lately that I am trying to overcome.

The problem is as follows.

I have been using a Microsoft.XMLHTTP ActiveX Object to login to the website and do all the test manipulation and form submitting. The recent changes to the website have broken the automation code. The original form that I was working with contained a submit button as follows

<input id="submitReq" type="submit" value="task device"/>

and the id allowed the ActiveX control to find the button and submit the form.

Now the page has changed as follows.

There is no longer a submit button instead there is a standard button calling a javascript onclick which is then used to submit the form. The button and the javascript are below and as you can see the button has no id which makes finding and submitting the button very difficult.

Code:
<input type="button" class="button" value="Task Devices" onclick="submitRequestForm()"/>


        <script type="text/javascript"> 
            <![CDATA[
            function submitRequestForm()
            {
                var validations = new Object();
                var fieldNames = ["devices", "profile", "priority"];
                for (var key in fieldNames) {
                    try
                    {
                        document.getElementById("errorMessageSpace_" + fieldNames[key]).innerHTML = "";
                    }
                    catch(ex)
                    {
                    }
                }
                validations["devices"] = [
                {type: "required", errorAction: displayTaskingParamError, errorMsg: "Devices field cannot be empty!"},
                {type: "mask", regExp: /^(([!]?[\+]?([*?0-9A-Fa-f]{0,30}))|(([!]?[\+]?[0-9A-Fa-f]{0,30})?\/([0-9A-Fa-f]{0,30})?\/([*?0-9A-Fa-f]{0,30})?))(\s(([!]?[\+]?([*?0-9A-Fa-f]{0,30}))|(([!]?[\+]?[0-9A-Fa-f]{0,30})?\/([0-9A-Fa-f]{0,30})?\/([0-9A-Fa-f]{0,30})?)))*$/, errorAction: displayTaskingParamError, errorMsg: "Invalid devices list specification!"}];
                validations["profile"] = [
                {type: "required", errorAction: displayTaskingParamError, errorMsg: "Profile field cannot be empty!"},
                {type: "mask", regExp: /^[0-9]*$/, errorAction: displayTaskingParamError, errorMsg: "Invalid profile specification!"}];
                validations["priority"] = [
                {type: "required", errorAction: displayTaskingParamError, errorMsg: "Priority field cannot be empty!"},
                {type: "mask", regExp: /^[+-]?[0-9]*$/, errorAction: displayTaskingParamError, errorMsg: "Invalid priority specification!"},
                {type: "numberBetween", low: 0, high: 1000, errorAction: displayTaskingParamError, errorMsg: "Priority value must be between 0 and 1000!"}];
                var taskingRequestForm = document.getElementById('taskingForm');
                taskingRequestForm.elements["devices"].value = normalizeDevicesList(taskingRequestForm.devices.value);
                if (new FormValidator(taskingRequestForm, validations).validate(false))
                {
                    taskingRequestForm.submit();
                }
            }
            
            function displayTaskingParamError(field, validation)
            {
                try
                {
                    document.getElementById("errorMessageSpace_" + (field.name || field.id)).innerHTML = "*" + validation["errorMsg"];
                }
                catch(ex)
                {
                    alert(validation["errorMsg"]);
                }
            }
            ]]>
        </script>

Can anyone tell me how to submit this page after the form is filled out using the Microsoft.XMLHTTP ActiveX Object? Is there a way?

Thanks in advance for any help that any of you can be.

Regards,
 
[0]
>but there always seemed to be a ton of JavaScript people around.
That's true.
>as I am a Java developer by Trade
Good, we have java forums that need talent like you to help others...
>Hello Everyone Smarter Than Me!
... so that you can show your talent there and prove that your are Smarter Than Most Others in your trade.

[1] This question has everything to do with javascript and has near to zero to do with activex. You should post the question to javascript forum in the followup related to the project.

[2] I can give you the answer for this. You can get to the "standard button" element and continue the task as if it is being clicked like this.
[tt]
var taskingRequestForm = document.getElementById('taskingForm');
var cinput=taskingRequestForm.getElementsByTagName("input");
for (var i=0; i<cinput.length;i++) {
if (cinput.value=="Task Devices") {
[blue]cinput.onclick()[/blue];
break;
}
}
[/tt]
 
[2.1] In case there might be elements with value "Task Device" as well (which eventually would happen one day as Murphy's Law trying to say) then you can guard against by checking the type as well (and if the more the better, className as well).
[tt]
var taskingRequestForm = document.getElementById('taskingForm');
var cinput=taskingRequestForm.getElementsByTagName("input");
for (var i=0; i<cinput.length;i++) {
if (cinput.type.toLowerCase()=="button" && cinput.value=="Task Devices") {
cinput.onclick();
break;
}
}
[/tt]
ps: The use of toLowerCase() is just another added safety measure. Common ie/moz return "button" in lower case as a norm. (Your target user agent sure would be ie as you test activex.)
 
Tsuji,

I appreciate your response as this will help me greatly in getting my code working properly again!

Thank you,

Zero
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top