How to click ok on a dialog box using UFT - hp-uft

I got a weird dialog box in web application testing and I am just stuck. Dialog box is a conditional. It displays based on some data we enter. I just need to be able to click OK or press enter if it displays.
I clicked OK while recording. UFT does not add any code and nothing was added to OR. When I spy, it is not recognizing the ok and does not recognize the dialog box.
Manually I simply click OK or press enter to handle. Then I wrote the shell way to press enter. It does not do anything.
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "{ENTER}"
Set WshShell = Nothing
How can I handle this dialog box using UFT?

you can you insight object to identify the "Ok" button. in case you are not able to spy it.

If this is the browser's regular dialog (javascript's alert) UFT supports dismissing it using Browser(...).HandleDialog.
If this works then it should also have recorded the HandleDialog step, if it doesn't it may be a defect in UFT, I suggest contacting MicroFocus's support.

Related

Detect and close "Windows Update" dialog box - vbscript .vbs file

I have the vbscript code to toggle between two windows:
Option Explicit
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
Do
WScript.Sleep 20000
WshShell.AppActivate("Inbox - Microsoft Outlook")
' WshShell.SendKeys "% r"
WScript.Sleep 20000
WshShell.AppActivate("Firefox")
' WshShell.SendKeys "% r"
Loop
The problem is, I get "Windows Update" dialog box randomly and it shows up on screen. Is there a way to find that dialog box and close it through existing vbscript that I have? Below is the picture of dialog box:
Appreciate any help.
Thanks,
Richa
I'm not sure if that dialog can be touched by VBScript unless you were to run it with admin privileges.
I think the easiest solution it to prevent Windows from automatically installing updates. Open up Windows Update from the Control Panel, go to Change Settings, then set it to one of
Download updates but let me choose whether to install them
Check for updates but let me choose whether to download and install them
If you choose the first one, I believe you'll get a taskbar notification (balloon) when there are updates available, which won't steal focus but still let you know updates are ready.
Given that Win7 is probably only going to receive Windows Defender definition updates for the rest of its lifetime, you probably won't encounter this dialog often now.

Disable the X button on a message box

I'm working on a VBScript program, and I don't know how to disable the X button on a message box. Can you please help me?
Short answer: You basically can't. However...
If you use the VbOkOnly option or Popup function in place of MsgBox, when the user clicks on X this should be interpreted as clicking OK. The execution of the script will be continued.
Click here for more info..
As #Daniel Cook said, you could make an HTA as your message box. (Even though I haven't been using HTA for a while).

Switching Internet Explorer Windows with VBA

I have been working on an Excel macro to automate an Internet Explorer process at work. I'm incredibly close to figuring everything out, but at the end, the macro clicks on a "Download Report" button, which launches a new window. I need to initiate a few things on this new window but I cannot figure out how to change the focus of the macro to the new window. I have found a few things online, but they have been unsuccessful. I know there are ways to toggle between browser windows by telling Excel to look for the name of the browser window, and to activate it, but parts of the name of the new window are constantly changing (it's a unique URL for that particular window).
I was wondering if there might be a way to have the Macro look for just the first Nine letters of the window and switch to that window? Similar to the LEFT function in excel? The reason being is that the first 9 characters of the URL never change. The name of the original window (the one I'm trying to switch from) never changes, so maybe I could tell Excel to look for the the Browser Window that is NOT named the original one? Or any other ideas?
Thanks in advance for any help
Is the VBA AppActivate command what you are looking for?
You will need to add the references to the Internet Controls and shell. You just need to loop through the IE windows and look at the left hand side of the url. See below
Function GetInternetWindow(urlToLookFor as String) As InternetExplorer
Dim winShell As Shell
Dim ie As InternetExplorer
Set winShell = New Shell
'loop through the windows and look at the urls
For Each ie In winShell.Windows
If Left(ie.LocationURL, 9) = urlToLookFor Then
GetInternetWindow = ie
Exit For
End If
Next
End Function

disable message box for programs that was run from cmd

I have util which at the end of it's work shows message box with notification and OK button. I run it under command line and would like to disable all message boxes that can break my process and require user reaction. Does any way to accoplish this task?
I would recommend just adding a --quiet command line switch instead, so users have better control over this kind of thing.
If you want to try to do it automatically, you can check the parent PID right when your app launches, and see if it's cmd.exe. Of course this is not 100% accurate because there are more scenarios where users don't want user interaction.
Well... you could use VBScript to automatically click or press ENTER on the messagebox. But you'll need to know the window name or number of the messagebox.
This code will bring focus to a Window called MESSAGEBOXNAME, and the press ENTER.
Set oShell = CreateObject("WScript.Shell")
oShell.AppActivate("MESSAGEBOXNAME")
WScript.Sleep 500
oShell.SendKeys "~"
Where MESSAGEBOXNAME is the Window Name of the MessageBox, that should be in the upper right corner of the messagebox.

AutoIt - Internet Explorer Navigate to another page (Pop Dialogue Box)

I am using AutoIT within Internet Explorer to navigate from one web page to another
The code I am using is:
_IENavigate($oIE, "http://www.google.co.uk")
However the web page that it is coming from displays a JavaScript popup box. I would like to click the OK button to allow the Navigation to proceed
I have tried using the following code:
ControlClick("Windows Internet Explorer", "", "[CLASS:Button; TEXT:OK; Instance:1;]")
However this doesn't work due to the fact that when the dialogue box appears the AutoIT process seems to pause itself.
The title on the dialogue box is "Windows Internet Explorer" and there are two buttons. The button I would like to click has the text of "OK"
Has anyone else come across this before? If so how can I solve this problem?
_IENavigate by default waits until the page is fully loaded. The dialog box may prevent a page to be fully loaded. The correct solution would be to:
_IENavigate the page without waiting for the page to fully load
Wait until the dialog box appears and close it
Wait for the page to fully load
The parameters for _IENavigate are like this, and you need to set $f_wait to 0:
_IENavigate(ByRef $o_object, $s_url [, $f_wait = 1])
To wait for the dialog box to appear, you will probably simply repeatedly attempt to click it until the ControlClick function returns it did so successfully.

Resources