How to change the selected option value using vbscript? - vbscript

There is a dropdown box on the web page with code:
<select
name="ctl00$ctl05$ddlCurrency"
id="ctl00_ctl05_ddlCurrency"
class="ddlCurrency"
style="font-size:x-small;width: 55px; background-color: #EDEEEF;">
<option value="AUD">AUD</option>
<option value="EUR">EUR</option>
<option value="GBP" selected="selected">GBP</option>
<option value="USD">USD</option>
</select>
Please, tell me how to change the selected option value "GBP" to value "USD" of a dropdown box in an IE window using vbscript?
Thanks,
Pers2012

Try this:
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "http://www.example.com/"
While ie.Busy : WScript.Sleep 100 : Wend
For Each opt In ie.document.getElementById("ctl00_ctl05_ddlCurrency").Options
If opt.Value = "USD" Then
opt.Selected = True
Else
opt.Selected = False
End If
Next

Related

I'm trying to select Payment option in select list in firefox browser but it is not selecting

Here im trying to select Payment option in select list and working on Firefox browser.
<select id="IDITForm#claimReserveReasonVO#id" class="SelectInput" onclick="closeAfterUnload = false" onblur="releaseCurrentFocusField()" helptextinfo="" onfocus="onFocusFieldHandler(this)" onchange="closeAfterUnload = false" onkeypress="onComboKeyPress(this)" style="width: 328px; visibility: visible;" name="IDITForm#claimReserveReasonVO#id" tabindex="217" origvalue="-1" value="-1">
<option value="-1">Select</option>
<option value="11">Damage Closed</option>
<option value="10">Ex- gratia</option>
<option value="4">Invoice</option>
<option value="6">Medical information</option>
<option value="1">Open new damage</option>
<option value="7">Payment</option>
<option value="3">Proposal</option>
<option value="5">Report assessor</option>
<option value="12">Storno payment</option>
</select>
I have tried using the following code but nothing succeeds
b.select_list(:id, 'IDITForm#claimReserveReasonVO#id').select "Payment"
b.select_list(:id, 'IDITForm#claimReserveReasonVO#id').option(:text,'Payment').select
b.select_list(:id, 'IDITForm#claimReserveReasonVO#id').option(:value,'7').select
but I have written the below code to print the options, it works fine, that is, It's printing all the options.
b.select_list(:id, 'IDITForm#claimReserveReasonVO#id').options.each do |option|
puts option.text
end
Note : It works perfectly in Chrome but not in Firefox.

HTA : how to pick up value from each drop down list and search?

I am trying to make this HTA working, what it does is to add up all value from each drop down list and search accordingly in a directory that can be selected from another button. I can only make the form of this HTA but dont know how to make the search working.
Also how can I move the directory selection button to the beginning of the line?
so user can pick up directory first then pick what they want to search.
<html>
<head>
<HTA:APPLICATION ID="2014-03"
applicationName="2014-03"
version="1.1"
BORDER="thin"
BORDERSTYLE="static"
CAPTION="Yes"
CONTEXTMENU="no"
ICON="C:\icon\32x32.ico"
INNERBORDER="no"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
NAVIGATABLE="no"
SCROLL="no"
SCROLLFLAT="no"
SELECTION="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal"
>
<SCRIPT LANGUAGE="VBScript">
Sub RunSearch_OnClick()
msgBox "Success!"
End Sub
Sub TestSub
For Each objOption in OptionChooser.Options
If objOption.Selected Then
Msgbox objOption.InnerText
End If
Next
End Sub
Sub TestSub1
For Each objOption in OptionChooser.Options
If objOption.Selected Then
Msgbox objOption.InnerText
End If
Next
End Sub
Sub WindowsLoad
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder (0, "Select The Folder To Enumerate :", (0))
If objFolder Is Nothing Then
Wscript.Quit
Else
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
End If
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder(objPath)
For each objFile in objFolder.Files
If objFolder.Files.Count > 0 Then
Window.Document.Title = "Information For " & objPath
strHtml = strHtml & "<td><Font color = Blue>" & objFile.Name & "</font></Br>"
DataArea.InnerHtml = strHtml
End If
Next
End Sub
</SCRIPT>
</head>
<body>
<select id=extension size="1" name="OptionChooser" onChange="TestSub">
<option value="0">Selet File Type</option>
<option value="1">.txt</option>
<option value="2">.pdf</option>
<option value="3">.jpg</option>
<option value="4">.mp3</option>
</select>
<select id=year size="1" name="OptionChooser" onChange="TestSub1">
<option value="0">Select Year</option>
<option value="1">2014</option>
<option value="2">2013</option>
<option value="3">2012</option>
<option value="3">2011</option>
<option value="3">2010</option>
</select>
<select id=month size="1" name="OptionChooser" onChange="TestSub2">
<option value="0">Select Month</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="1">04</option>
<option value="2">05</option>
<option value="3">06</option>
<option value="1">07</option>
<option value="2">08</option>
<option value="3">09</option>
<option value="1">10</option>
<option value="2">11</option>
<option value="3">12</option>
</select>
<input Type = "Button" Value = "Browse For Folder" Name = "Run_Button" onClick = "WindowsLoad"><p></td>
<input type="button" value="Search" name="RunSearch">
</body>
</html>
The final HTA should look like this, the search result need to be displayed below the drop down list as text file within a scrollable window and having full path of the files.
In next HTA only necessary changes made to display the search result below the drop down list as a scrollable text area and having full paths of the files.
On start, a user is prompted to select initial directory (see WindowsLoad call within the Window_Onload procedure; then all files are displayed as no search criteria selected yet.
Search completed in code for extension only to show a possible how-to approach (one of few).
Used a simple StyleSheet.
Some variables defined script (application) global to keep their visibility within all procedures.
Further elementary changes: see the code below.
The code:
<html>
<head>
<HTA:APPLICATION ID="2014-03"
applicationName="2014-03"
version="1.1"
BORDER="thin"
BORDERSTYLE="static"
CAPTION="Yes"
CONTEXTMENU="no"
ICON="C:\icon\32x32.ico"
INNERBORDER="no"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
NAVIGATABLE="no"
SCROLL="no"
SCROLLFLAT="no"
SELECTION="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal"
>
<!--
'************************
'* StyleSheet
'************************
-->
<style>
BODY
{
background-color: buttonface;
font-family: Arial, Helvetica, sans-serif;
font-size: 8pt;
margin-top: 2px;
margin-left: 8px;
margin-right: 3px;
margin-bottom: 3px;
}
.button
{
font-family: Arial, Helvetica, sans-serif;
font-size: 8pt;
width: 40px;
}
textarea
{
background-color: yellow;
font-family: Arial;
font-size: 8pt;
margin-left: 3px;
margin-right: 3px;
}
</style>
<SCRIPT LANGUAGE="VBScript">
'************************
'* Global Variables
'************************
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
objPath = ""
strHtml = ""
Chooser0 = ""
Chooser1 = ""
Chooser2 = ""
'************************
'* Window_Onload
'************************
Sub Window_Onload
self.Focus()
self.ResizeTo 800,600
DataArea.InnerHTML = "<textarea cols=122 rows=25></textarea>"
WindowsLoad
End Sub
Sub RunSearch_OnClick()
'msgBox "Success!"
WindowsLoad
End Sub
Sub TestSub
If OptionChooser.Value = "0" Then
Chooser0 = ""
Else
For Each objOption in OptionChooser.Options
If objOption.Selected Then
Chooser0 = objOption.InnerText
Exit For
End If
Next
End If
End Sub
Sub TestSub1
For Each objOption in OptionChooser1.Options
If objOption.Selected Then
Msgbox objOption.InnerText
End If
Next
End Sub
Sub TestSub2
For Each objOption in OptionChooser2.Options
If objOption.Selected Then
Msgbox objOption.InnerText
End If
Next
End Sub
Sub whichFolder
prevPath = objPath
Set objFolder = objShell.BrowseForFolder _
(0, "Select The Folder To Enumerate :", (0))
If objFolder Is Nothing Then
msgBox "Bye!"
self.Close()
Else
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
End If
If prevPath <> "" then WindowsLoad
End Sub
Sub WindowsLoad
If objPath = "" Then
whichFolder
End If
Set objFolder = objFso.GetFolder(objPath)
Window.Document.Title = "Information For " & objPath & " " & Chooser0
strHtml = "<textarea cols=122 rows=25>"
ShowSubFolders objFolder, Chooser0
DataArea.InnerHtml = strHtml
End Sub
Sub ShowSubFolders(fFolder, strExt)
'strHtml = strHtml & Chr(10) & fFolder.Path & Chr(10)
Set objFolder = objFSO.GetFolder(fFolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
If strExt = "" OR UCase(strExt) = _
"." & UCase(objFSO.GetExtensionName(objFile.name)) Then
strHtml = strHtml & objFile.Path & Chr(10)
End If
Next
For Each Subfolder in fFolder.SubFolders
ShowSubFolders Subfolder, strExt
Next
End Sub
</SCRIPT>
</head>
<body>
<select id=extension size="1" name="OptionChooser" onChange="TestSub">
<option value="0">Selet File Type</option>
<option value="1">.txt</option>
<option value="2">.pdf</option>
<option value="3">.jpg</option>
<option value="4">.mp3</option>
</select>
<select id=year size="1" name="OptionChooser1" onChange="TestSub1">
<option value="0">Select Year</option>
<option value="1">2014</option>
<option value="2">2013</option>
<option value="3">2012</option>
<option value="3">2011</option>
<option value="3">2010</option>
</select>
<select id=month size="1" name="OptionChooser2" onChange="TestSub2">
<option value="0">Select Month</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="1">04</option>
<option value="2">05</option>
<option value="3">06</option>
<option value="1">07</option>
<option value="2">08</option>
<option value="3">09</option>
<option value="1">10</option>
<option value="2">11</option>
<option value="3">12</option>
</select>
<input Type = "button" Value = "Browse For Folder"
Name = "Run_Button" onClick = "whichFolder"><p>
<input type="button" value="Search" name="RunSearch"><p>
<div id="DataArea" name="DataArea"></div>
</body>
</html>

How to auto click on image

Set IE = CreateObject("internetexplorer.Application")
IE.Visible = 1
IE.navigate "https://dashboard.opendns.com/settings/"
Do While (IE.Busy)
WScript.Sleep 10
Loop
Set Helem = IE.document.getElementByID("username")
Helem.Value = " "
Set Helem = IE.document.getElementByID("password")
Helem.Value = " "
IE.Application.document.getElementById("sign-in").Click
WScript.Sleep 10
<a id="dip22332965" title="Update this text" href="#"
onclick="update_ip(22332965);return false" img width="11" height="13"
style="border: 0pt none; margin-bottom: 1px;"
src="https://d2v7u03x06aro3.cloudfront.net/img/icon_update_small.gif">
I successfully sign in after clicking the button, but how can I click on image automatically as mentioned above script?

Combobox if selected not working

I have a combobox where I submit a value when Onchange event is triggerd. But the 'if' won't work.
The ID and the 'selectedGebouw' are both visible on the screen combobox, but it won't let it as selected.
<select name="gebouwFilter" onchange="this.form.submit()">
<option value="0"></option>
<%
set objRec = objCon.execute(QUERY)
DO WHILE NOT objRec.EOF
%>
<option value="<%=objRec("locationID")%>" <%if selectedGebouw = objRec("locationID") then response.write("Selected") end if %>>
<!-- <%=objRec("address") &", "& objRec("place") %> -->
<%=objRec("locationID") &", "& selectedGebouw %>
</option>
<%
objRec.MoveNext
Loop
objRec.Close
set objRec = nothing
%>
</select>
FIXED:
First changed the submited value to int fixed it:
selectedGebouw = cint(Request.Form("gebouwFilter"))

Form validation in an HTA file

How can I perform a simple validation on this HTA form to make sure that data is inputted and an option is selected? This should be simple, I'm not sure what I'm missing.
Any answers or suggestions would be appreciated.
Thanks.
<html><head><title>Write data to text file</title>
<HTA:APPLICATION
border="thin"
borderStyle="normal"
caption="yes"
maximizeButton="no"
minimizeButton="yes"
showInTaskbar="yes"
innerBorder="yes"
navigable="yes"
scroll="auto"
scrollFlat="yes" />
<script language="javascript">
window.resizeTo(480,150)
function Writedata()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var write_id;
write_id = document.getElementById('write_id').value ;
alert('The data has been written to \n' + write_id);
var s = fso.OpenTextFile(write_id, 8, true);
s.WriteLine(document.getElementById('name_id').value);
s.Close();
}
</script>
</head>
<body>
<table>
<tr>
<h3>Input some information</h3>
<form>
<td>Input: </td><td><input type="text" name="name" value="" id="name_id"></td>
<td><select id="write_id">
<option name="write" value="">Select an Option</option>
<option name="write" value="C:\temp\option1.txt">Option1</option>
<option name="write" value="C:\temp\option2.txt">Option2</option>
</select></td>
<td><input type="button" onclick="Writedata()" value="submit"></td>
</form>
</tr>
</table>
</body>
</html>
I was stumped, so I rewrote this in vbscript.
I have included bits of what I did to give you an idea of how to write to a text file, and validate your form with an HTA.
The vbscript:
Set wshShell = CreateObject( "WScript.Shell" )
strSender = wshShell.ExpandEnvironmentStrings( "%USERNAME%" ) ' Get the current Username
Dim Checkmark
Sub Validate
If form.Flag.checked = True Then ' Find out if your Checkbox is checked
Checkmark = "*"
Else
Checkmark = ""
End IF
If form.field1.value = "" Then ' Validate the form
alert "Please enter an number!", "0", "Title"
ElseIf IsNumeric(form.field1.value) = False Then
alert "Please enter a valid number!", "0", "Title"
ElseIf form.drop_down1.Value = "" Then
alert "Please select a save location!", "0", "Title"
ElseIf form.field1.value < 100000 Then
alert "Please enter a six digit number!", "0", "Title"
ElseIf form.field1.value > 999999 Then
alert "Please enter a six digit number!", "0", "Title"
Else
SaveData
End If
End Sub
Sub SaveData ' Write data to a text file
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(form.drop_down1.Value) Then
Set objFile = objFSO.OpenTextFile(form.drop_down1.Value, 8)
strLine = form.field1.value & vbtab & Checkmark & vbtab & strSender & vbtab & Now ' fields that will be written
objFile.WriteLine strLine
MsgBox "The Information was successfully written to the file.", "0", "Title"
objFile.Close
Else
Set objFile = objFSO.CreateTextFile(form.drop_down1.Value) ' If file does not exist, create file
strLine = form.field1.value & vbtab & Checkmark & vbtab & strSender & vbtab & Now
objFile.WriteLine strLine
MsgBox "The Information was successfully written to the file.", "0", "Title"
objFile.Close
End If
End Sub
The HTML:
<form name="form">
<h2>Imput</h2>
<tr><td><lable>Data: </lable></td><td><input type="text" name="field1" size="25"></td> </tr>
<tr><td><lable>Save Location: </lable></td><td><select name="drop_down1">
<option type="text" name="select" value="">Select an option</option>
<option type="text" value="SavePath1...">SavePath1</option>
<option type="text" value="SavePath2...">SavePath2</option>
<option type="text" value="SavePath3...">SavePath3</option>
</select></td><td><input type="checkbox" name="Flag" value="">Flag *</td></tr>
</table>
<input type="button" value="Submit" onClick="Validate">
<input type='reset' id='ResetFields' value='Clear Fields' />
</form>

Resources