In my application , by clicking the save button, the dialog prompts a message with OK button. While recording 'the OK button' got recorded and shows 'text_ok().click(atpoint(11,8));'. But during play back it shows me a 'Object not found' error.
Recently updated the RFT Version 8.2.2.1 after this only this issue is seen.
Can anyone say me how to solve this problem or any coding in java.
My regression is waiting due to this, your help is highly appreciable.
Thanks in Advance.
You have not mentioned what type of dialog window it is. But you can try the IWindow API of RFT to find active top window and perform the click as specifed below.
The Following code for eg can handle an alert dialog box in html by calling
handleDialogButton("Message from Webpage", "ok");
Or,to click on canel button on Notepad's Font dialog (Format>Font) by calling
handleDialogButton("font","cancel");
-------Sample code----
/*
* Activates the top window with the given caption and clicks on the child control(window) with the specified text
* #param caption- Caption of the Dialog window
* #param btnToClick- Text of the button(any other control) to click
*/
void handleDialogButton(String caption,String btnToClick)
{
IWindow[] windows = getTopWindows();
for(IWindow window: windows)
{
if(window.getText().equalsIgnoreCase(caption))
{
window.activate();
//window.close(); //we can just close it also n break.
IWindow[] children = window.getChildren(); // OR go thru the children to get the child
for(IWindow child:children)
{
if(child.getText().equalsIgnoreCase(btnToClick))
{
child.click();
break;
}
}
}
}
unregisterAll();
}
From the poing of Selenium Web driver API i recommend you do the following:
Alert alert = driver.switchTo().alert();
alert.accept();
Hope this works for you
Related
I have encountered a problem when using the the addCommand() method of the Form class along with the Native theme - other themes work fine. See the following example:
Form hi = new Form("Hi World");
hi.addComponent(new Label("Hi World"));
// with native theme - can't click on the first command in the list
hi.addCommand(new Command("Dummy1") {
public void actionPerformed(ActionEvent ev) {
Dialog.show("Dummy1 Clicked!", "You clicked the Dummy1", "OK", null);
}
});
hi.addCommand(new Command("Dummy2") {
public void actionPerformed(ActionEvent ev) {
Dialog.show("Dummy2 Clicked!", "You clicked the Dummy2", "OK", null);
}
});
hi.show();
When I create an application using the code above, a click on the second command ("Dummy2") produces the expected Dialog, but a click on the first command ("Dummy1") does nothing.
This only happens when using the Native theme. If I switch to Flat Blue, then clicking on either command produces the expected Dialog.
This behavior happens both on the Simulator and on a real Android device (don't know about iOS).
Fyi, my toolchain is NetBeans IDE v8.2, Java 1.8.0_25, with the CodenameOne plugin v3.6.0.
Has anyone else seen this? Am I missing something? If so, is there a workaround?
If the element is very narrow and very close to the top the click might be misinterpreted as a click out of bounds or on the status bar area. You need to set the styling of the SideCommand to have a sensible default as this element is very application specific. Otherwise touches might be lost.
I tried styling the SideCommand but it didn't seem to help. What worked for me was to define a style for TitleArea and simply uncheck Derived for the Padding settings (I left them all set to 0px).
I have no idea why this works - I would have thought that the derived values would have been zero in any case.
While doing handle windows in selenium - Java, in Java it shows one 1 window open and if i tried with C# it shows 2 . I am not able to get the window handle of second window opened(Actually it is a message dialog box, i need to click on ok button and proceed to the parent window) in Java.Please help me to sort this out
You should have searched for solution on internet and tried it yourself first, well below code might help you:
//Before you click, get main window handle
String mainhandle=driver.getWindowHandle();
//Enter code to click button
new WebDriverWait(driver, 60)
.ignoring(NoAlertPresentException.class)
.until(ExpectedConditions.alertIsPresent());
flag=0;
while(flag==0){
try{
driver.switchTo().alert().accept();
flag=1;
}
catch(Exception e){
driver.manage().timeouts().implicitlyWait(1,TimeUnit.SECONDS);
}
}
driver.switchTo().window(mainhandle);
I am working with Selenium, now there is a condition:
when I hit a button in my webpage a window pop up opens up.
Now I have to click a radio button (one out of two, it will work even if we send a TAB ) and then click an OK button. I searched in the net and got to know about "driver.getWindowHandle()".
But I don't have any idea dealing with the newly opened window popup.
Need help in this.
For switching purpose u can use enhanced for loop:
for (String winHandle : objDriver.getWindowHandles()) {
objDriver.switchTo().window(winHandle);
}
So it will switch the control from one driver window to child windows.
To interact with elements on the window try to find element with whatever tool u r using and perform the required action after switching to the window.
To return back to parent window you can use the same loop or use:
driver.switchTo().defaultContent();
Check my answer in this post and also read the comments to help you understand the difference between getWindowHandle() and getWindowHandles()
Java: focus is not on pop-window during window handling
We handled this situation using AutoItX - https://www.autoitscript.com/site/ in our Windows/IE C# project:
AutoItX3 autoIt = new AutoItX3();
var handle = autoIt.WinWaitActive("[window title]", "", 20);
Assert.IsTrue(handle != 0", string.Format("Was not able to find: {0}", [window title]);
autoIt.Send("{ESCAPE}"); // tab may work as well for selection
The pop up was a Windows window, and not part of IE, therefore the WebDriver didn't know about it.
Hope this helps.
I am trying to catch SWT events, like SWT.activate, SWT.deactivate and SWT.dispose in Eclipse. So, I can see which dialog was opened or activated, which was closed and which was deactivated. If the event was caught, I extract the Shell object and extracts its title with shell.getText(). To listen to events, I used an untyped listener (edited):
PlatformUI.getWorkbench().getDisplay().addFilter(SWT.Activate, shellListener);
Listener shellListener = new Listener(){
#Override public void handleEvent(Event e) {
if (event.widget.getClass() == org.eclipse.swt.widgets.Shell.class){
Shell shell = (Shell) e.widget;
String shellTitle = shell.getText();
if (event.type == Activate) {
String message = "The following dialog was activated: " + shellTitle;
// do other stuff with 'message'
}
}
}
};
If in Eclipse I open 'New' and the listener above correctly displays 'New' as activated dialog. But if I select 'Java Interface' within the 'New' dialog, then I am landing in a dialog, called 'New Java Interface'. But my handleEvent method is not fired and therefore I cannot extract the new dialog title. My question is: What kind of event is called or what happens, when I am in an Eclipse dialog and clicking on something in it which leads me to another dialog (with a new title)?
I think the problem here comes from the fact that the New 'dialog' in Eclipse is actually a Wizard. When you select 'Java Interface' (in the 'New' dialog) you are actually then landing not in another dialog but on a page within the same wizard. Every page in this wizard can have it's own title but behind the scene it is the same underlying shell object, that is why you don't receive further events.
By the way: when working with the SWT.Activate, SWT.Deactivate and other similar shell events, it might be helpflul / easier to the a ShellAdapter
I am working on J2ME application. I want to show alert in Form and display another Form from another class. I have tried the following method to show alert.
public void showMsg()
{
Alert success = new Alert("Data Not found.");
//success.setImage(img2);
success.addCommand(new Command("Ok", Command.OK, 0));
success.addCommand(new Command("Cancel", Command.CANCEL, 0));
success.setCommandListener(this);
success.setTimeout(Alert.FOREVER);
Display.getDisplay(parent).setCurrent(success, chapterForm);
}
After showing the alert I am jumping to another form as:
Display.getDisplay(parent).setCurrent(welcomeForm);
When I run this it don't show the alert but jump to the welComeForm. So, how can I show alert and then jump to another form.
The Alert won't advance automatically to chapterForm because you have replaced the default listener on the Alert with this. Use the commandAction() event in the CommandListener interface to get the OK or Cancel from the Alert. Then you can use Display.setCurrent(Displayable d) to show the Form you want to display.
Display.getDisplay(parent).setCurrent(welcomeForm) is most likely the reason why it don't show the alert but jump to the welComeForm. To be precise it (device) may show alert for a moment, but as soon as you invoke that setCurrent(welcomeForm), it gets momentarily overwritten by welcomeForm.
If you want welcomeForm to be dissplayed by command from alert, just
wipe out the code setCurrent(welcomeForm) from where it is now
insert that wiped-out code into this.commandAction method (this is command listener you use in your code exerpt)
A nifty solution is to start a new thread after setting the current display to the Alert, and in this new thread you can do a Thread.sleep(2000); in order to wait, and after that you display the new form.