We're creating a HTA file so withe the information the user has input, we can automate the process of logging a ticket. The user will input the information in the HTA form and click Submit. This will then open a link in IE, input the data from the HTA to the relevant fields and then automatically click the Submit button at the end of the page.
The majority of it works so far but I'm unable to automate the Submit action. I've checked various forums but haven't been able to get this working with any suggestions so far. I'm just looking for a way to automate clicking the submit button in the IE window.
There are 3 buttons on the IE page and I'm not sure how to specify I want to click submit.
New to VBScript so any help is much appreciated.
<input value="Reset" onclick="return myReset();" class="secondary" type="button">
<input value="Add to a Bundle" onclick="return myAddRequisition();" class="secondary" name="submitorderform" type="submit">
<input value="Submit " onclick="return myOrderNow();" class="primary" name="submitorderform" type="submit">
I think the code that you posted is kind of weird, since it has two buttons with the same name.
I assume that the webpage in IE to which the information is to be sent contains only one form.
I also assume that an instance of IE automation object is stored in IE variable.
After you filled out the form via your HTA programmatically, if you want to simulate a click on the button "Add to bundle" , use the code below:
var frm = IE.document.forms[0];
for (var i = 0;i < frm.elements.length;i++)
if (frm.elements[i].type == "submit" && frm.elements[i].value == "Add to a Bundle")
frm.elements[i].click();
Or, if you want to click on the button "Submit ", you can use the code above, but be sure to replace "Add to a Bundle" with "Submit ".
Edit: In VBScript, you can use the code below:
Dim frm, i
Set frm = IE.document.forms.item(0)
For i = 0 to frm.elements.length - 1
If frm.elements.item(i).value = "Add to a Bundle" And frm.elements.item(i).type = "submit" Then
frm.elements.item(i).click
End If
Next
Edit 2: According to your comments, i guess you don't wait for your webpage until it is completely loaded. Thus, you get an Unspecified Error. To solve this problem, you should set an interval to repeatedly check if IE.ReadyState equals 4. To do so, use the code below after calling Navigate method of IE:
Dim interval
interval = window.setInterval(GetRef("fillOutForm"), 1000)
Sub fillOutForm()
If IE.ReadyState = 4 Then
window.clearInterval interval
'Here place code that fills out the form in the webpage and submits it.
End If
End Sub
As you can see, you should call setInterval method and set the first parameter to a function pointer. Use the GetRef function to obtain a function pointer. In the code that I sent, I passed a pointer to the subroutine fillOutForm. So this subroutine will be called every 1 second. In this subroutine, you check if IE.ReadyState equals 4 then you fill out the form and submit it.
Related
There is a web site I need to scrape. I can fill in the necessary data. The problem is that I don't understand how to press the button to get the page with results.
The button has the following code:
<input type="button" value="Search!" onclick="SearchSmth();" id="btSearch">
So because the type is not 'submit' attempts to use Browser.submit() fail. I tried using something like this:
resp = b.click(type="button", id="btSearch")
but it also failed:
ClientForm.ControlNotFoundError: no control matching type 'button', kind 'clickable', id 'btSearch'
What should I do to get this button pressed?
Have you used zope.testbrowser? This is wrapper over mechanize module of python. You can use getControl browser.getControl(name='text-value') method of zope.testbrowser. You can see more examples here
I have a dev express calendar . Now, the requirement is that i need to print a particular record. But the problem is that, the record details open in a pop up and i need to print only the popup page. But when i used print on the page it printed the whole page i.e. the pop up and side stuff on the main page.
This is what i did:
<input type="button" value="Print Form" onclick="window.print()" />
So, can u let me know what i need to do to print only the pop up. (excluding page stuff)
In my ASP.NET app using the crystal report viewer (ver 13.0.2000.0), when the user clicks "Print" and then either prints or cancels out of printing, when they next Drill Down in the report it will hang forever with the crystal dialog "Please wait while the document is being processed" with spinning triangle circle animation.
It does this in IE and Firefox, but it does NOT do this in Chrome: Instead the print button launches the PDF export with the "The viewer must export to PDF to print." messaging. This is what older versions of crystal did.
Right now I'm going down the road of forcing IE and Firefox to do the same thing as chrome - but if there's a real solution to the print problem - I'd rather use that. It seems when a user clicks Print (vs. export) they want to print (vs. export).
I came up with a work around for this. Since Crystal Reports does not allow overriding the buttons I ended up hiding the print button and adding my own print button using JavaScript/jQuery.
Here is some under-the-hood info on how the printing works. When you press the print button it does a postback with the view states and event arguments. The post back returns a PDF file which the browser opens inline. The PDF file is embedded with a print command which is executed when the file is opened.
So what we can do is use a hidden IFRAME to load the printable PDF. This way the main page is not affected. I think the PDF loading inline is what causes the page/browser to corrupt its state.
Place the below code at the top of your ASPX page. You must place it at the top of the page otherwise the print dialog will be off the screen if you put it at the bottom.
Here is the HTML:
<iframe id="HiddenFrame" name="HiddenFrame" style="display: none;"></iframe>
<form id="PrintForm" action="MyPage.aspx" method="post" target="HiddenFrame">
<!-- Change the name if your object is not named 'CrystalReportViewer1' -->
<input type="hidden" name="__CRYSTALSTATECrystalReportViewer1" id="CRState" />
<input type="hidden" name="__VIEWSTATE" id="VState" />
<!-- Change this value to match your CrystalReportViewer object's name. -->
<input type="hidden" name="__EVENTTARGET" value="CrystalReportViewer1" />
<!-- This is the print command that is sent. -->
<input type="hidden" name="__EVENTARGUMENT" value='{"text":"PDF", "range":"false", "tb":"crpdfprint"}' />
</form>
As mentioned above, the IFRAME will load our PDF. The form is used to do a POST to the server with the view states and event arguments. The target attribute tells the form to load in the IFRAME.
Here is the JavaScript:
// Hide the print button.
$('#CrystalReportViewer1_toptoolbar_print').hide();
// Inject our own print button. You can apply the same icon to your print button using CSS to make it look like the original icon.
$('#CrystalReportViewer1_toptoolbar_print').parent().append('<div id="PrintButtonOverride"></div>');
// When user clicks our print button, copy the states and submit the form.
$('#PrintButtonOverride').click(function () {
$('#CRState').val($('#__CRYSTALSTATECrystalReportViewer1').val());
$('#VState').val($('#__VIEWSTATE').val());
$('#PrintForm').submit();
});
The click event copies the two view states from the main page and then submits the form. I wrote this post quickly so I apologize if I left something unclear.
Is there a way with ASP.net page (with AJAX) to display some some of busy indicator (just a label is fine) while disabling some buttons (to prevent double-click) and then do the work. At the end of the work, the label changes to indicate the new status.
When I tried to do it this way :
Public Sub BtnEnvoyer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnEnvoyer.Click
BtnEnvoyer.Enabled = False
LblStatus.Visible = True
LblStatus.ForeColor = Drawing.Color.ForestGreen
LblStatus.Text = "Envoi en cours..."
SendEmail()
End Sub
Private Sub EnvoyerCourriel()
' Do some work
LblStatus.Text = "Done!"
BtnEnvoyer.Enabled = True
End Sub
I just see the dn result, nothing in between.
I don't mind using javascript to make it work if needed, or anything else for that matter.
I asked a very similar question a few weeks ago:
ASP.NET Custom Button Control - How to Override OnClientClick But Preserve Existing Behaviour?
The class i created can be dropped onto any form and will prevent double-clicks.
Essentially, i am setting the button to "disabled", but there is nothing stopping you from extending that to call your own client-side code.
You're best bet is to disable the button (like i did), and also show a hidden DIV which contains an animated gif (AJAX loading image).
You might find the discussion on this question helpful:
ASP.Net double-click problem
The solution(s) deal only with the button, but you could extend the idea to disabling more of the DOM and showing a hidden div with your message as part of the client click function.
You should be able to use a bit of jQuery to find the buttons, and disabled them. When I've done this in the past I've also changed the text of the button to "Please Wait...". I wired up the client onclick in conjunction with the postback of the button.
It worked great for me as it stopped the button from being pressed again and also gave the user an immediate visual feedback that they'd successfully clicked the button.
If you need an example I'm sure I can dig out some code for you.
If you want the page to be updated before the postback result comes back, you'll have to use javascript, something like this. This is a general approach, that you should probably customize to what you need.
In your html:
<head>
<script type="text/javascript">
function ShowWait() {
document.getElementById('labelspan').innerText = 'Loading...';
}
</script>
</head>
In the page setup:
BtnEnvoyer.OnClientClick = "ShowWait();";
Then when the button is clicked, ShowWait will apply whatever visual effects you want while the postback is actually processing. As soon as it's ready, the whole page will be replaced with the results of the postback.
Here's the scenario:
I have a textbox and a button on a web page. When the button is clicked, I want a popup window to open (using Thickbox) that will show all items that match the value entered in the textbox. I am currently using the IFrame implementation of Thickbox. The problem is that the URL to show is hardcoded into the "alt' attribute of the button. What I really need is for the "alt" attribute to pass along the value in the textbox to the popup.
Here is the code so far:
<input type="textbox" id="tb" />
<input alt="Search.aspx?KeepThis=true&TB_iframe=true&height=500&width=700" class="thickbox" title="Search" type="button" value="Search" />
Ideally, I would like to put the textbox value into the Search.aspx url but I can't seem to figure out how to do that. My current alternative is to use jQuery to set the click function of the Search button to call a web service that will set some values in the ASP.NET session. The Search.aspx page will then use the session variables to do the search. However, this is a bit flaky since it seems like there will always be the possibility that the search executes before the session variables are set.
Just handle the onclick of your button to run a function that calls tb_show(), passing the value of the text box. Something like
... onclick = "doSearch()" ...
function doSearch()
{
tb_show(caption, 'Search.aspx?KeepThis=true&q=\"' +
$('input#tb').val() +
'\"&TB_iframe=true&height=500&width=700');
}
If you read the manual, under the iframe content section, it tells you that your parameters need to go before the TB_iframe parameter. Everything after this gets stripped off.
Here is an idea. I don't think it is very pretty but should work:
$('input#tb').blur(function(){
var url = $('input.thickbox').attr('alt');
var tbVal = $(this).val();
// add the textbox value into the query string here
// url = ..
$('input.thickbox').attr('alt', url);
});
Basically, you update the button alt tag every time the textbox loses focus. Instead, you could also listen to key strokes and update after every one.
As far as updateing the query string, I'll let you figure out the best way. I can see putting a placeholder in there like: &TB=TB_PLACEHOLDER. Then you can just do a string replace.
In the code-behind you could also just add the alt tag progammatically,
button1.Attributes.Add("alt", "Search.aspx?KeepThis=true&TB_iframe=true&height=500&width=700");