I am trying to click a link on a page, it don't have any id and not having a unique class name. Only unique thing about the function is the onclick handler
<a href="#" onclick="closepopup('popup', 'popuphandler')" > </a>
I need to click this link via vbscript automation, for the same i tried the code as:
Set allLinks = ie.document.links
for j = 0 to allLinks.length-1
if allLinks(j).onClick = "closePopup(""popup"",""popupClose"")" then
allLinks(j).click
j = allLinks.length 'class name = blueButtonCenter
end if
Next
But it is not working, please help.
Thanks in advance :)
You didn't specify what doens't work, finding the link or clicking it, in the first case:
onClick wil return something like
about:blank# function onclick()
{
closepopup('popup', 'popuphandler')
}
so you shoudl use instr to check if it is the right link
Dim HTMLDoc, XML, URL, table
Set HTMLDoc = CreateObject("HTMLFile")
Set XML = CreateObject("MSXML2.XMLHTTP")
URL = "your url"
With XML
.Open "GET", URL, False
.Send
HTMLDoc.Write .responseText
End With
Set allLinks = HTMLDoc.links
For each link in allLinks
if instr(link.onClick, "closepopup('popup', 'popuphandler')") then
link.click
exit for
end if
Next
Only the click won't work this way..
I would try to check if the closePupup is found in the actual javascript, like so:
'safety first
if not isnull(allLinks(j).onClick) then
if instr(allLinks(j).onClick.toString() , "closePopup(""popup"",""popupClose"")" ) > -1 then
allLinks(j).click
j = allLinks.length 'class name = blueButtonCenter
end if
end if
This assumens onClick delivers a string, (at least in javascript it does and in IE9 and Chrome this works)
Related
I want to use VBScript to click a button that reads “Add Document” in the GUI of an application that runs in Internet Explorer. The problem is there is no “id”, “name” , or “class” element in the source code (see below) to use as a reference in the script.
Source Code:
<TD>
<INPUT type="button" value="Add Document" onclick="addFileUploadBox()">
</TD>
My code is below and works for elements that have source code ids. Also included are some failed attempts to click the button in question based on my googling but I cant get to work. I'm new to this and any help would be appreciated - any suggestions to fix?
My Code:
Dim objIE
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate "http://sharemxxxx.xxxxx.com/xxxImport/import.aspx"
While objIE.Busy
WScript.Sleep 100
Wend
objIE.Document.getElementById("txtReferenceNum").value = "15226002"
objIE.Document.getElementById("ddlCategory").value = "05"
objIE.Document.getElementById("btnRetrieve").click
' ABOVE CODE WORKS
' NOT WORKING #1 - DOES NOTHING - NO ERROR
'===========================================
objIE.Document.getElementByType("btn").Value="Add Document"
For Each btn In objIE.Document.getElementsByTagName("input")
If btn.Value="Add Document"Then btn.Click()
Next
' NOT WORKING #2 - DOES NOTHING - NO ERROR
'===========================================
For Each Button In objIE.Document.getElementsByTagName("input")
If Button.Value="Add Document"Then Button.Click()
Next
' NOT WORKING #3 - DOES NOTHING - NO ERROR
'===========================================
Set oInputs = objIE.Document.getElementsByTagName("input")
For Each elm In oInputs
If elm.Value = "Add Document" Then
elm.Click
Exit For
End If
Next
' NOT WORKING #4 - Show Empty Msg Box
'===========================================
set objButtons = objIE.document.getElementsByTagName("input")
for each objButton in objButtons
strText = objButton.innerhtml
msgbox strText
if (strText = "Add Document") then
msgbox "found the button!"
objButton.click
exit for
end if
next
You probably don't even need to find the element. It looks like the button just calls a JavaScript function. So you can use the execScript() function to run it.
For example:
objIE.Document.parentWindow.execScript "addFileUploadBox();", "javascript"
So I have the following code on my asp page that should hide/unhide a textbox depending on the two conditions and whether or not they are both met.
if request.form("Requester_Presenter") = 1 and request.form("Additional_Presenters") = 0 then
ErrorMessage = ErrorMessage + "<dd>- If you are not a presenter, there must be additional presenters selected so you can provide their contact information in the next step.</dd>"
document.form.presenters.style.display = "none"
end if
if request.form("Requester_Presenter") = 0 and request.form("Addition_Presenters") = 0 then'do something'
document.form.presenters.style.display = "block"
end if
when I run my code however, I get the following error:
Microsoft VBScript runtime error '800a01a8'
Object required: 'document'
which says that I am experiencing my error on the line where I set the textbox to display: none; or display:block;
What am I doing wrong here?
Classic ASP (vbScript) is a Server side scripting language and what you're trying to do is mix Server side code with client side code (document is available in javascript and represent the current loaded page in the DOM)
What you can do, is embed this code inside a script html tag and have it output some javascript :
<script type="text/javascript">
<%
if request.form("Requester_Presenter") = 1 and request.form("Additional_Presenters") = 0 then
ErrorMessage = ErrorMessage + "<dd>- If you are not a presenter, there must be additional presenters selected so you can provide their contact information in the next step.</dd>"
%>
document.form.presenters.style.display = "none"
<%
end if
if request.form("Requester_Presenter") = 0 and request.form("Addition_Presenters") = 0 then 'do something'
%>
document.form.presenters.style.display = "block"
<% end if %>
</script>
I have a web form that when the button is pressed should pull a list of names from a field and send a mail. The mail isn't sending.... Here is the lotus script... thanks in advance
Sub Click(Source As Button)
Dim s As New NotesSession
Dim ws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim mdoc As NotesDocument
Dim ddoc As NotesDocument
If ws.CurrentDocument.IsNewDoc Then
Call ws.CurrentDocument.Save
Set db = s.CurrentDatabase
Set view = db.GetView("deptLookup")
Set doc = ws.CurrentDocument.Document
dept$ = doc.ProcDeptAssoc(0)
Set ddoc = view.GetDocumentByKey(dept$)
If ddoc Is Nothing Then
Msgbox "Department not found"
Else
Set mdoc = New NotesDocument(db)
mdoc.Subject = "Comment made on procedure " + doc.ProcNo(0) +" - "+doc.ProcName(0)+ " by " + doc.CreatedBy(0)
Dim rtitem As New NotesRichTextItem(mdoc, "Body")
Call rtitem.AppendText("Requires the approval of " +doc.approver(0)+", click the link and the approve or deny the request. ")
Call rtitem.AddNewline(1)
Call rtitem.AppendDocLink(doc, "CommentsDoc")
receipients = ddoc.NotifyName
mdoc.SendTo = receipients
mdoc.Send(False)
End If
Else
Call ws.CurrentDocument.Save
End If
ws.CurrentDocument.Close
End Sub
If you use a form instead of an XPage you will need to place your code in the agent and set that agent as WebQuerySave agent of the form. LotusScript under the button will not run when accessed from the web.
Also you cannot use UI classes like NotesUIWorkspace in backend code.
You can move that Lotusscript code to an agent with trigger "agent list selection" and target "none" and from the web form to use a #formula (not lotusscript) button with this #command:
#Command([RunAgent];"NAME_OF_YOUR_AGENT");
Panu Haaramoroperties is right when he says than the Lotusscript click event in buttons doesn't works from web forms but #commands do work.
He es also right when he said the you have to replace NotesUIWorkspace reference. You can begin using :
s.documentContext
instead
ws.CurrentDocument
I'm new to this site. I have searched thoroughly for an answer and cannot seem to locate an answer. I hope one of you fine people will be able to help me....
Thank you
When I try to run my custom form with code show below, I get the following message:
Script Error
Expected statement
Line No:33
Code:
Function Item_Open()
Dim LeaveItem
Dim IO
If not Connection_Open Then
MsgBox("Error connecting to SI")
LeaveItem = True
Item_Open = False
Else
Item_Open = False
End If
End Function
Function Item_Close()
If LeaveItem = True Then
Exit_Function
Else
End If
End Function
Subroutine Connection_Open()
Dim oSI
Set oSI = New ADODB.Connection
Dim ostrSI
oSI.ConnectionString = "Driver={Progress OpenEdge 10.1C Driver};HOST=192.168.1.1;DB=kob;UID=sii;PWD=sisys1;PORT=2501;"
oSI.Open
End Sub
Change
Subroutine Connection_Open()
to
Sub Connection_Open()
I want to load a ".tdm" file into DIAdem (National Instruments) with a VBScript but can't find how to do this. I have Dialog which opens a browse-window, which returns the path as a string. So I was hoping to have a function which would work something like this:
Call Data.Root.ChannelGroups.Load(myStringWithThePath)
Just noticed I got a tumbleweed-badge on this question. Here is the solution I found last week, so if anybody cares:
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "TDM-Datei(*.tdm)|*.tdm|All Files (*.*)|*.*"
objDialog.FilterIndex = 1
boolResult = objDialog.ShowOpen
If boolResult <> 0 Then
Call Data.Root.ChannelGroups.RemoveAll()
Call DataDelAll
Call DataFileLoad(objDialog.FileName)
End If