My question is: I want to find the name of currently opened dialog(being displayed on top of all views) and finally reload it. Can anyone guide me for this ?
If the dialog is focused, you can access its Shell via:
Shell active = Display.getCurrent().getActiveShell();
String title = active.getText();
If you are using Eclipse RCP, you can do the same by using:
Shell active = PlatformUI.getWorkbench().getDisplay().getActiveShell();
String title = active.getText();
Related
I am new to windows automation using win app driver.
Our application is developed with chromium browser and we are using win app diver to automate since the main app we are trying to open is windows based.
When I click on Ok button opens another window(Window B). I have 2 windows opened window 1 and window 2. I need to perform actions on both the windows for that I need to shift the focus between two windows. When I use getwindowhandles() method I am getting number of windows opened as 1.
How can I switch between windows using winapp driver.
Appreciate your help.
Thanks
I am using in my code:
this.driver.SwitchTo().Window(this.driver.WindowHandles[0]);
However, I do not expect this to work in your case, as your number of open windows is 1, than means that there is no second window to switch to.
So in your case you can use root session in order to attach to your window:
AppiumOptions rootSessionOptions = new AppiumOptions();
rootSessionOptions.AddAdditionalCapability("app", "Root");
rootSessionOptions.AddAdditionalCapability("deviceName", "WindowsPC");
_driver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), rootSessionOptions);
_driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
var VSWindow = _driver.FindElementByName("Your project name without .csproj - Microsoft Visual Studio");
var VSTopLevelWindowHandle = VSWindow.GetAttribute("NativeWindowHandle");
VSTopLevelWindowHandle = (int.Parse(VSTopLevelWindowHandle)).ToString("x");
AppiumOptions VisualStudioSessionOptions = new AppiumOptions();
VisualStudioSessionOptions.AddAdditionalCapability("appTopLevelWindow", VSTopLevelWindowHandle);
_driver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), VisualStudioSessionOptions);
_driver.SwitchTo().Window(_driver.WindowHandles[0]);
Reference:
https://github.com/microsoft/WinAppDriver/issues/978
OpenQA.Selenium.WebDriverException: [windowHandle] is not a top level window handle solution
This code works for me (windows automation using win app driver) with C#
//Switch to the next window in desktop application:
IList<string> toWindowHandles = new List<string>(_driver.WindowHandles);
Thread.Sleep(6000);
_driver.SwitchTo().Window(_driver.WindowHandles[0]);
With Java:
Thread.sleep(5000);
//Switch to the next window in desktop application:
Set<String> windowHandles = driver.getWindowHandles();
driver.switchTo().window(windowHandles.iterator().next());
Here is my specific scenario:
I have my application running in the background and I want to open a new window from my applications toolbar icon right click menu. For simplicity I am using a MessageDialog, and using the method open() on the dialog, the window should display and make itself the active window.
For some reason I've run into the problem that if I had some other application open and I try to open this new dialog, it opens, but behind the active application. The new dialog will open in front of the other windows of the same application, but not the other(active) application.
Is there a simple way to do this that I'm missing?
I was able to find a solution. Essentially you need to find your active workbench shell(the application shell) and use the following methods on that shell, followed by pushing the actual desired window to the front.
You could easily modify this to make your window appear maximized as well by adding the method shell.setMaximized(true) before the redraw.
private static void bringupDialog(WindowState state) {
final Shell workbenchShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
//bring up the application to front
workbenchShell.setVisible( true );
workbenchShell.setMinimized( false );
workbenchShell.redraw();
//focus on dialog
workbenchShell.setActive();
workbenchShell.forceActive();
workbenchShell.setFocus();
workbenchShell.forceFocus();
workbenchShell.moveAbove( null );
workbenchShell.redraw();
Shell shell = instance.getShell(); // desired window shell
shell.setActive();
shell.forceActive();
shell.setFocus();
shell.forceFocus();
shell.moveAbove( null );
shell.redraw();
}
Is there some easy way to reopen closed tabs in Netbeans RCP application?
I have a module application with several modules that each has some topComponents (explorers, editors etc.) but when I close some tab (using the "x" symbol), it stays closed even during next startup and I cant seem to find any way how to restore it.
All the components contains #TopComponent.Registration(mode = "explorer", openAtStartup = true)
The components also contains this:
#TopComponent.Description(
preferredID = "ProductionExplorer",
//iconBase="SET/PATH/TO/ICON/HERE",
persistenceType = TopComponent.PERSISTENCE_ALWAYS
)
What am I missing here?
The persitence type of the top component is set to "always", that means the state of the component will allways be stored when you close the application. Whether it is closed or opened. If you change to PERSISTENCE_NEVER, it won't be saved.
To reset the windows you have to use the menu item "Reset Windows" under "Windows".
I inherited a Java app built (I believe) in Eclipse, which I'm modifying using NetBeans 7.4. I want to set the main menu title which shows up on a Mac next to the Apple menu. Right now that name is MainForm, but I want it to change dynamically to the contents of a specific text file (name.txt). I've looked up tons of info on project.properties, ANT scripts, and the like, but I can't find a definitive (and hopefully cross-platform) way to set this main menu title. I have a function in my code that returns this name, so I can use that if there's a place to do it. Thanks in advance!
I have found that in order to set the App Name in Mac OS X Application Menu, and avoid having it show up as the name of your Java project, you have to set it VERY early in the application cycle, using System.setProperty("apple.awt.application.name", "Your App Name");
Here's how I have mine set in my "main" java method that launches the application:
public static void main(String[] args) {
// the application menu for Mac OS X must be set very early in the cycle
String opSysName = System.getProperty("os.name").toLowerCase();
if (opSysName.contains("mac")) {
// to set the name of the app in the Mac App menu:
System.setProperty("apple.awt.application.name", "Your App Name");
//to show the menu bar at the top of the screen:
System.setProperty("apple.laf.useScreenMenuBar", "true");
// to show a more mac-like file dialog box
System.setProperty("apple.awt.fileDialogForDirectories", "true");
//underlying laf:
javax.swing.UIManager.getInstalledLookAndFeels();
// other set-up code goes here
}
else { // not on Mac OS X
// set-up code for non-Mac systems
}
java.awt.EventQueue.invokeLater(() -> {
// run the program
});
}
I am using three instances of fire fox driver for automation.I need to bring current active firefox browser into front, Because I am using some robo classes for some opertation. I had tried java script alert for google chrome in mac ( same operation) and its worked fine. In windows used user32 lib. In the case of firefox mac its showing the alert in background but the web page is not come into front.
((JavascriptExecutor)this.webDriver).executeScript("alert('Test')");
this.webDriver.switchTo().alert().accept();
The above code I used for chrome in Mac. Same code is working and showing alert for firefox but the window is not coming to front.
Please suggest if there any other method for doing the same in firefox.
Store the window handle first in a variable, and then use it to go back to the window later on.
//Store the current window handle
String currentWindowHandle = this.webDriver.getWindowHandle();
//run your javascript and alert code
((JavascriptExecutor)this.webDriver).executeScript("alert('Test')");
this.webDriver.switchTo().alert().accept();
//Switch back to to the window using the handle saved earlier
this.webDriver.switchTo().window(currentWindowHandle);
Additionally, you can try to maximise the window after switching to it, which should also activate it.
this.webDriver.manage().window().maximize();
Try switching using the window name:
driver.switchTo().window("windowName");
Alternatively, you can pass a "window handle" to the switchTo().window() method. Knowing this, it’s possible to iterate over every open window like so:
for (String handle : driver.getWindowHandles()) {
driver.switchTo().window(handle);
}
Based on the Selenium documentation: http://docs.seleniumhq.org/docs/03_webdriver.jsp
As described in other topics, you can use
driver.manage().window().setPosition(new Point(-2000, 0));
too.
# notifications for selenium
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs", prefs)
current_path = os.getcwd() # current working path
chrome_path = os.path.join(current_path, 'chromedriver')
browser = webdriver.Chrome(executable_path=chrome_path, chrome_options=chrome_options)
browser.switch_to.window(browser.current_window_handle)
browser.implicitly_wait(30)
browser.maximize_window()
browser.get("http://facebook.com")
Only thing that worked for me on mac: self.driver.fullscreen_window().