Need VBScript Code to toggle between two Webpages to copy content from one page and paste to another webpage - vbscript

I am need of VBScript code to paste the content from one IE Explorer WebPage window to another IE Explorer WebPage window.
Currently i know the Process ID.
However I am not able to switch from one webpage to another. Or you can say my control does not move from one page to another.

#shellbye
Function Bmc(abc,xyz)
Set objIE = CreateObject("InternetExplorer.Application")
Call objIE.Navigate("// SOME APLLICATION") ' #opened the Web applcation
'# LOGGED INTO THE APPLCATION SUCCESSFULLY suing the VBScript
For i = 0 To objIE.Document.links.Length - 1
if objIE.Document.links(i).innerText ="Create a New Case" Then
Do Until objIE.ReadyState = PAGE_LOADED : Call WScript.Sleep(100) : Loop
objIE.Document.links(i).click '## THIS OPENS A NEW Window as link is an URL
Exit For
End If
End Function
In above, I am able to Open the new window after clicking the link i.e. at Step ##
Now I want to copy the content abc and xyz passed in the function Bmc(abc,xyz) to New Window opened through this.
However I am unable to move or us can say switch control to new window.

Related

Blocking code in custom message box in VB6

In my vb6 project, I created my own msgbox using a form, due to difficulties in changing
the font/language of in-built msgbox. A search with google gave the idea of own msg-
box rather than trying msgbox of VB. Now the problem is : - when the user exits the
program, 3 options are given: to close, to restart and to cancel exit. The user need not
again go through the process of giving password etc in restart option. If I give cancel =
true in the QueryUnload event, then 2nd option does not work, 3rd option works. If
cancel = true is not given, 2nd option works, but 3rd option does not. It appears that
the main form does not get unloaded if cancel = true. Unless & until the main form
unloads, the program will not work with the fresh data to be given by the user in the
initial Form. Since the code after "msgbox.show" depends on options, it is not possible
to write that code in the same sub, not even in the same form code. Is there any way
to stop the subsequent code after "msgbox.show" and continue the same after getting
option? (like in the in-built msgbox of VB.) I am not an expert in VB, so please correct
if I made some mistake; also help with advice/suggestions.
EDIT:- [Extended explanation]
The 3 forms in my project:
Initial form for password, data etc. This is input Form for user.
Main Form. This Form shows the results after process of input.
frmMsgBox. This is a custom msgbox created using a form.
Main Form code portion. Code for closing the program:
Private Sub Form_QueryUnload(Cancel as.......)
cancel = True
frmMsgBox.Label1.caption = Do you wish to 1.Exit 2.Restart
3.Cancel the exit?
frmMsgBox.Show
End sub
(The above msgbox is almost like an in-built msgbox in VB with
vbYesNoCancel buttons) The message is in regional language,
which was the main reason forced me to use my own msgbox.
After MsgBox appears, the user selects one of the above options
using 3 commandButtons placed in that Form. The code after
clicking these buttons is written in the code portion of frmMsgBox:
Command1_Click 'This is for Exit from the Program.
All Forms.unload, All forms set to nothing, end.
Command2_click 'This is for restarting the Program.
Unload Main Form, set to nothing
Load Initial Form
Initial Fom.show
frmMsgBox.Hide
Command3_Click 'This is for cancelling the exit request.
Main Form.Show
frmMsgBox.Hide
With the above code, I have no problem with options 1 & 3,
i.e; to exit from the program or to start. The frmMsgBox hides,
the initial form shows - these are OK, but the main form does
not unload nor it is removed from memory. Because of this,
whatever new data is given by the user in the initial form now
is not being processed, the main form is struck with the old results.
If cancel = true is removed from the code above, Options 1 & 2
are OK, but option 3 does not work. Then the Main Form loses
all its results (all labels, texts etc in that Form turn blank.)

Create VBScript script detect iexplore

I want to create a VBScript script to detect Internet Explorer opening page and opening new tab in the same window. For example, when I manually open Internet Explorer at www.google.com the VBScript will do:
detect and open new tab in same window with www.example.com
but do this only once
I tried with this code:
Set wshShell = CreateObject("WScript.Shell")
Do
page1 = wshShell.AppActivate("Blank page - Internet Explorer")
If page1 = True Then
Set page2 = CreateObject("InternetExplorer.Application")
page2.Navigate "http://www.example.com", CLng(navOpenInNewTab)
End If
WScript.Sleep 500
Loop
For one thing, you must use the existing Internet Explorer instance instead of creating a new one. Unfortunately the way one might expect to be able to do that (GetObject(, "InternetExplorer.Application")) does not work for Internet Explorer COM objects. AppActivate also doesn't help here, because it doesn't return a handle to the application object, which you need to invoke its methods. Instead you need to do it this way:
Set app = CreateObject("Shell.Application")
For Each wnd In app.Windows
If InStr(1, wnd.FullName, "iexplore.exe", vbTextCompare) > 0 Then
Set ie = wnd
Exit For
End If
Next
If you want to select an instance that has a particular page opened, you can for instance check the title of that page to make the selection:
wnd.Document.Title = "something"
or
InStr(1, wnd.Document.Title, "something", vbTextCompare) > 0
Your second problem is that VBScript doesn't recognize the symbolic constant navOpenInNewTab. You must either use the numeric value (as defined in the BrowserNavConstants enumeration):
ie.Navigate "http://www.example.com", CLng(2048)
or define the constant yourself first:
Const navOpenInNewTab = &h0800&
ie.Navigate "http://www.example.com", navOpenInNewTab
Note that you must use hexadecimal notation with a trailing ampersand here, because the value must be a Long and you must use literals in Const definitions. Expressions like calling the function CLng are not valid.
Alternatively you can open a URL in a new tab by omitting the second parameter of the Navigate method entirely and instead providing the value "_blank" for the third parameter:
ie.Navigate "http://www.example.com", , "_blank"
However, I'm not certain that this would always open a new tab in the current window (might depend on the browser's tab settings), so I'd recommend using the second parameter (flags) as described above.

How to wait for page load for any browser

During test run, multiple tabs get opened in chrome. As it is opening the new tabs, I would like UFT to wait until complete page loads. I am trying to make it a standard wait without waiting for a specific object.
For example, during run chrome opened, launched URL, click a link, new tab opened, now for the new page to load. Then click a link from 2nd tab and wait for the 3rd page to be loaded.
How can I force UFT to wait for the last page loaded assuming there are multiple tabs?
This will wait till all page is downloaded.
Browser().Page().Sync
This will wait for particular object
Browser().Page().Object().Waitproperty
If you want for property of object(s) to change, loop it, like
Do Until WaitProperty = Argument
print "Wait. Progress "&Progress
wait 3 'wait 3 seconds
Progress = Progress+"." 'add a period to show progress
Set ObjColl = MyBrowser.ChildObjects(WObj)
WaitProperty = cstr(ObjColl(t).GetROProperty(Arg4)) 'get the object property
Loop
To loop through all pages in a browser:
'Get Pages count:
Set browserObject = Description.Create
browserObject("micclass").Value = "Browser"
GetBrowserCount = Desktop.ChildObjects(browserObject).Count
'loop and sync (or any other methods):
for i = 0 to GetBrowserCount-1
browser().page("micclass:=Page","CreationTime:="&i,"Title:=.*").Sync
next
You can use .Sync for each browser opened also you can use .WaitProperty "visible","true" in order to wait for a property of an object displayed.

unable to save changes in our web application when running VB test script using testcomplete 11.0

I have Recorded a VB test script in TestComplete 11.0 and did some changes in our web application. when i was running the recorded test script, i didnt get any errors in log file which was generated by TestComplete but changes are not reflecting in our application.
Here is the VB Test Script:
Sub Test1
Dim browser
Dim page
Dim form
Dim textbox
Dim table
TestedApps.XXXcm.Run
Call Browsers.Item(btIExplorer).Navigate("http://localhost/XXXcm/connect.asp")
Set browser = Aliases.browser
Set page = browser.pageXXXConfigurationManager
Set form = page.formConnectform
Set textbox = form.textboxUsername
Call textbox.Drag(89, 12, -244, 6)
Call textbox.SetText("admin")
Call textbox.Keys("[Tab]")
Set table = form.tableYYYYtable
Call table.passwordboxPwd.SetText("XXXX")
table.submitbuttonLogin.ClickButton
page.Wait
Set page = browser.pageXXXConfigurationManagerField
Set textbox = page.tableDbfieldtable.cellColrubrik.textboxShortname
Call textbox.Click(85, 12)
Call page.Keys(" ")
Call textbox.SetText("Mobileno")
delay(5000)
page.buttonSave.ClickButton
page.Wait
End Sub
Could you please suggest me on this.
Thanks and Regards,
Sailaja
Try replacing SetText with Keys. SetText sets the text programmatically and may not trigger some keyboard events that you application may be listening to. Keys simulates actual typing on a keyboard.
To always record tests using Keys, go to Tools > Options > Engines > Recording and change the Record text input... option to Keys.

VB6 Common Dialog Control File Open does not give correct folder on some Windows 7 PCs

My VB6 application uses the Common Dialog Control for File Open etc.
The code is working OK on hundreds of PCs.
But I have one customer for which the File Open command displays the wrong folder.
He's running Windows 7.
Here's an excerpt of my code:
Private Sub mnuFileItem_Click(Index As Integer)
CommonDialog1.FileName = "" 'workaround for problem with .InitDir (20051010)
CommonDialog1.InitDir = strDataPath
' Set filters
CommonDialog1.Filter = ApplicationName & " Files (*" & PreProcessorFileExtension & ")|*" & PreProcessorFileExtension
' Set dialog box so error occurs if the dialog box is cancelled '20020418
CommonDialog1.CancelError = True
Select Case Index ' Check index value of selected menu item.
Case 0 ' If index = 0, the user chose "New"
'code omitted here
Case 1 ' If index = 1, the user chose "Open..."
' display the File Open dialog
CommonDialog1.Action = 1
FileName = CommonDialog1.FileName
OpenCLSFile
Case 2 To 3 'If index = 2, "Save..." = 3, "Save As..."
'code omitted here
End Select
End Sub
Typically the variable used to define CommonDialog1.InitDir, strDataPath, is set to:
C:\Users\Public\Documents\Mincad Systems\CIRCLY5\data
But for the user that has the problem, the File Open dialog displays:
C:\Users\Public\Documents\Mincad Systems\CIRCLY6\data
I have logs from the user that confirm that CommonDialog1.InitDir =
C:\Users\Public\Documents\Mincad Systems\CIRCLY5\data
before every statement in Sub mnuFileItem_Click.
The user is also using a vb.net version of my application.
In that application the File Open dialog uses the folder:
C:\Users\Public\Documents\Mincad Systems\CIRCLY6\data
Is there some way that the vb.net application resets some property of the Common Dialog Control properties used by the VB6 application?
I have tried replacing the VB6 Common Dialog File Open by using a Win32 API version - but my user still has the same problem.
Regards,
Leigh
I know this post is old, but maybe this will help someone. What I found in my case is that if the directory you are setting Initdir to does not exist on that PC, then the current directory is used.

Resources