I want to put my subroutines in an external file. When I press the help button it pops up errors. Even at startup it shows errors. If I put the contents of scripts.vbs within the HTA they work fine.
Here is the code:
Contents of scripts.vbs file:
Sub Window_Onload
Msgbox "welcome"
end sub
Sub Help
MsgBox "This is an example of progressbar in HTA written by Fredledingue.",,MyTitle
End Sub
Contents of HTA file:
<script type="text/vbscript" src="scripts.vbs">
</script>
<body bgcolor="GreenYellow">
<input id="BtnHelp" type="button" value="Help" onclick="Help">
Importing the script file like that should work, as long as the HTA and VBScript files are located in the same folder. You need to make sure that the <script> tag is closed though:
<script type="text/vbscript" src="scripts.vbs"></script>
If you still get errors you need to show them (full error message, including error number and the line raising the error).
With that said, I'd recommend against externalizing code from HTAs, because it reduces mobility. A self-contained HTA can easily be copied to wherever you like. The need to keep several files together has a negative impact on that.
Related
Is there a way to prompt a user for input (several arguments) and pass the input to a command prompt using HTA/VBScript? The command may take anywhere between 1-2 minutes to run before the next command is executed. This command returns "results" which I would like to display at the bottom of a window in a frame. This could be tricky since I don't know if there is a return code to check for.
For example: The quick brown input1 jumped over the lazy input2
The user would have to input in the textbox "fox dog" delimited by either a space or a comma. If the command executes successfully, it will say "the fox was able to jump over the dog" - if the command fails, it will say "the fox fell short".
Several different commands would have to be executed one after another as long as the previous command completes successfully.
I'm going to answer this as you're not sure where to start and you're thinking about programming an HTA like it is Basic - prompt user -> print answer - when it is actually more like visual basic where you have a form with input boxes and buttons and code that interacts with that form.
The "form" in an HTA is created using HTML (so you need to know some HTML) and the code that interacts with the HTML objects is either Javascript or VBscript*.
I beleive that HTAs offer a great way experiment with programming without having to install servers or import code libraries etc. You can just open Notepad** and start writing code.
You can copy the code below that does roughly what you describe in your question and use it as a starting point to experiment more.
<html>
<style>
#output {font-size:2em;}
</style>
<script language="vbscript">
sub updateText_OnClick
output.innerHTML = "The quick brown " & input1.value & " jumped over the lazy " & input2.value
end sub
</script>
<body>
Brown: <input type="text" name="input1"/>
Lazy: <input type="text" name="input2"/>
<input type="button" name="updateText" value="update"/>
<br/><br/>
<div id="output">The quick brown ? jumped over the lazy ?</div>
</body>
</html>
** You can use something like Notepad++ or another code editing program that will highlight your code and make it easier to spot if you have forgotten to close your quotes "" or misspelled a word.
*VBscript no longer works if you use the meta tag for IE 11 and above.
More example scripts https://gallery.technet.microsoft.com/ScriptCenter/site/search/?f%5B0%5D.Type=SearchText&f%5B0%5D.Value=HTA&x=0&y=0
I recommend the HTA helpomatic as it has useful code snippets.
First of all I'm a complete beginner when it comes to VBscripts.
I have only one asp file written in VB that starts a batch file.
The thing is that I want something that indicates that the page is loading like a gif. The batch takes almost 10 minutes to run and what I get is a blank page until it is finnished.
This is my entire code
<%# Language = VBScript %>
<HTML>
<script runat="server" language=VBScript>
' The batch file is running here
Dim myExecutor
Dim commandline
commandline = "cmd.exe /c C:\test.bat "
Set myExecutor = Server.CreateObject("WScript.Shell")
myExecutor.Run commandline,0,true
Set myExecutor = Nothing
Response.Write "The batch run is finnished <p> "
</script>
<body>
The batch is loading. <!--renders after batch is finnished :/ -->
</body>
</HTML>
I tried to run an onclick event <asp:Button Text="Click here" OnClick="run_batch" runat="server"/> but gives me a 500 page error when i use the sender As Object, e As EventArgs as parameters probably because I dont have the classes and only runns everything in one asp file.
Thanks.
The problem is that your code will execute as soon as the page loads. Define what you want to do as a Sub and call that in the onload event handler. The event will fire once everything on the page is loaded.
I tested the following in an hta and it works. Not sure how well it converts to asp.
<HTML>
<script language=VBScript>
sub DoStuff()
document.Write "<p>Doing stuff </p>"
CreateObject("WScript.Shell").Run "ping localhost",0,true
document.Write "<p>The batch run is finished <p> "
end sub
</script>
<body onload="DoStuff()">
</body>
</HTML>
Alternatively for a button approach just use
<button onclick="DoStuff()"> Do Stuff </button>
I am attempting to test my rails app's alert messages. I have the following code that is produced inside of Twitter Bootstrap:
<div class="alert fade in alert-success">
<button class="close" data-dismiss="alert">×</button>
Signed out successfully.
</div>
What I am trying to do is pull out just the "Signed out successfully."
At the moment I have:
def alert_text
#page.find('div.alert').text
end
But that gives me "× Signed in successfully."
In my test I am doing:
assert_equal "Signed in successfully.", my_page.alert_text
If I change the assertion to include the ×, I am getting a invalid multibyte char (US-ASCII) error. Is there an easy way to pull out the text and ignore the button? I would wrap the text in a separate div, but it is generated in the gem so I can't.
Since its hard to see what else is going on, I would add a custom element with id="signedOut" or something around the specific text, and access it by id. It won't mess with your boostrap styling.
Alternatively, try being more specific in the find. You may be using two classes that start with alert.
def alert_text
#page.find('div.alert fade in alert-success').text
end
If you have two div's using this class, you can add on to the end of it or just go into the class definition in your bootstrap folder and add one more layer to it. (Bootstrap uses js and css just like the rest of us, although it helps get things off the ground pretty quickly).
I am trying to catch an event in the VBSCRIPT of an html page but I can't make it work. I must have missed a step.
This is the code of my usercontrol (VB6):
Public Event sendText(ByVal Text As String)
Private Sub Command1_Click()
RaiseEvent sendText(Text1.Text)
End Sub
And this is the code of my web page (HTML):
<form>
<OBJECT name="ActiveX" id="ActiveX" classid="clsid:..."></OBJECT>
<script language="VBScript">
Sub ActiveX_sendText(Text)
Msgbox("aaa" & Text)
End Sub
</script>
</form>
The Event is raised in the user control when clicking the Command1 button, but I never get into the VBSCRIPT function.
I am using IE8/IE8 Standard.
Any clue?
It was a problem in the configuration of security rules in Internet Explorer. After enabling unsigned ActiveX, the issue was solved.
How to automate Uploading a file using selenium.
How to give file Path ??
My TextBox is Readonly. I cant type the file path directly in the textbox.
Also, how to stop the selinum server until that file completely uploaded.??
My File upload field is a invisible field. And i found its code using firebug add on.
Before adding a file code is like this.
<input id="ctl00_ContentPlaceHolder1_AsyncfileUpload_ClientState" type="hidden" name="ctl00_ContentPlaceHolder1_AsyncfileUpload_ClientState" autocomplete="off" value="{'isEnabled':'true','uploadedFiles':[]}">
And after adding a file(doc file). The code changed to
<input id="ctl00_ContentPlaceHolder1_AsyncfileUpload_ClientState" type="hidden" name="ctl00_ContentPlaceHolder1_AsyncfileUpload_ClientState" autocomplete="off" value="{'isEnabled':'true','uploadedFiles':[{"fileInfo":{"FileName":"scope.docx","ContentType":"application/vnd.openxmlformats-officedocument.wordprocessingml.document","ContentLength":12887},"metaData":"/wEFsAF7IlRlbXBGaWxlTmFtZSI6ImZyeWd1NGNqLmt1YSIsIkFzeW5jVXBsb2FkVHlwZU5hbWUiOiJUZWxlcmlrLldlYi5VSS5VcGxvYWRlZEZpbGVJbmZvLCBUZWxlcmlrLldlYi5VSSwgVmVyc2lvbj0yMDExLjEuNTE5LjM1LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPTEyMWZhZTc4MTY1YmEzZDQiffOraDjiYXPavAAMYOUAVVhGEKk8"}]}">
What is the Xpath here?
I tried with xpath id="ctl00_ContentPlaceHolder1_AsyncfileUpload_ClientState". The code which i used is
selenium.type("id="ctl00_ContentPlaceHolder1_AsyncfileUpload_ClientState","c:\\docfile1.doc");
But its not working.
Help Me..
The XPath expression for this input would be //input[#id='ctl00_ContentPlaceHolder1_AsyncfileUpload_ClientState'].
However, I fear this won't work since Selenium usually refuses to work with invisible elements. Also, hidden <inputs> are usually just containers for pre-filled data or containers for script-validated-and-edited data.
You should be looking for a <input type='file' /> if there's some, or maybe a javascript handling the click on the enclosing element (but, frankly, that's usually not the case - the scripts tend to act on edit of the input, not on the click on them).
If you can't find it, post some more code. The best thing would be a SSCCE, so take the source of the page and make it naked, strip everything unnecessary for us from it. We love code. And we love anything that's naked.
And about the wait for the upload to be complete: There's no such default thing. If the file is sent during a usual form upload (by clicking the Submit button), then the browser will wait. If it is uploaded immediately, you'll have to wait smartly. Realize what changes after a successful upload, then wait for that element/message to appear. With Selenium 2 (WebDriver), this can be done very easily.
You can use
selenium.type("xpath of text box","path of your file")
OR for IDE
command=type
target=xpath_of_text_box
value=Path_of_your_file
example:
selenium.type("id=cvfile", "D:\\Automation\\resume.doc");