TaskDialog default button - windows-7

stackoverflow just works faster :)
I'm using the Windows® API Code Pack for Microsoft® .NET Framework to access Windows 7 API and I want to change my old MessageBox to TaskDialog.
One thing I cannot find is the default button of the dialog. Is there a way to set it? what about a work around?
thanks

There is a Default property on a control under the taskbased dialog you can set to true. From the sample (Samples\TaskDialogDemo\CS\TaskDialogDemo) that ships with it:
TaskDialog tdEnableDisable = new TaskDialog();
tdEnableDisable.Cancelable = true;
tdEnableDisable.Caption = "Enable/Disable Sample";
tdEnableDisable.InstructionText = "Click on the buttons to enable or disable the radiobutton.";
enableButton = new TaskDialogButton("enableButton", "Enable");
enableButton.Default = true;
enableButton.Click += new EventHandler(enableButton_Click);
If you run the demo, click Enable/Disable sample and then press Enter a few times you will see that the two buttons take turns being the default.

Related

Invoking a button press in a desktop application from an external application when HWND and control automation ID are known

I am trying to automate button presses for a desktop application on Windows 7 - 10. I have been able to do this using AutoHotKey and PowerShell. However, I have had the following issues:
The controls I am trying to click do not have text that I can use to
isolate the control
The ClassNN name for the components is not
static
I have looked through the MSDN documentation for the System.Windows.Automation namespace, but the documentation doesn't provide actual examples or describe how to use the namespace.
Question
If I always have a window handle (HWND) and an Automation ID for a control, how do I invoke a button press on the control using AutoHotKey, PowerShell(3.0+), or C#?
You can do it with C# and System.Windows.Automation.
First of all get your control as an AutomationElement (let's call it thiselement).
Then you can invoke InvokePattern to perform click action.
InvokePattern ip;
ip = thiselement.GetCurrentPattern(InvokePattern.Pattern) as
InvokePattern;
ip.Invoke();
Suppose your window handle is 'handle' and automation id of the button is 'automationId' then you can do something like
AutomationElement parentWin = AutomationElement.FromHandle(handle);
Condition c1 = new PropertyCondition(AutomationElement.AutomationIdProperty,
automationId);
AutomationElement thiselement = parentWin.FindFirst(TreeScope.Descendants, c1);
once you get the button object,just invoke the InvokePattern .Please forgive the foramatting of text

How can you prevent the "Update Links" dialog to appear when opening documents from code?

I'm trying to Update Links of inDesign documents using ExtendScript, but whenever I open the document the dialog appear asking me if I want to update the link.
I want to do it in the background, so is there a way to prevent this or any dialog from showing?
Thanks
I have found a solution for this particular dialog. This prompt can be disabled from the UI, but also, as with other setting of the application, you can also do in the code.
So here is what I implemented.
//Save the current application setting.
var currentAppSettings = {checkLinksAtOpen: app.linkingPreferences.checkLinksAtOpen};
//Set the value to false to prevent the dialog from showing.
app.linkingPreferences.checkLinksAtOpen = false;
//do some stuff ...
//Set the value back to its original value.
app.linkingPreferences.checkLinksAtOpen = currentAppSettings.checkLinksAtOpen;
There is a setting in InDesign for checking links. What if you modified the default settings in InDesign? Perhaps if you uncheck "Check Links Before Opening Document" it will bypass the dialogue.

How to make Firefox open all links opened via WebDriver in the same window?

I want to open all links in the same window instead in new window.
I tried
profile.setPreference("browser.link.open_newwindow", 1)
but the result is:
WARNING: traffic.loop 0 error: Preference browser.link.open_external may not be overridden: frozen value=2, requested value=1
Is there an another way to open the links in the same window ?
You should modify the firefox profile parameters:
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.link.open_newwindow", 3)
profile.set_preference("browser.link.open_newwindow.restriction", 0)
driver = webdriver.Firefox(firefox_profile=profile)
if this methode does not work, you can set perference using firefox Options:
from selenium.webdriver.firefox.options import Options
opts = Options()
opts.set_preference("browser.link.open_newwindow.restriction", 0)
opts.set_preference("browser.link.open_newwindow", 3)
driver = webdriver.Firefox(firefox_options=opts)
(A) browser.link.open_newwindow - for links in Firefox tabs :
3 : divert new window to a new tab (default)
2 : allow link to open a new window
1 : force new window into same tab
(B) browser.link.open_newwindow.restriction - for links in Firefox tabs
0 : apply the setting under (A) to ALL new windows (even script windows)
2 : apply the setting under (A) to normal windows, but NOT to script windows
with features (default)
1 : override the setting under (A) and always use new windows
I've found a workaround!
JavascriptExecutor js = (JavascriptExecutor) driver;
String script = "document.getElementById('yourFormOrAnchorId').target=''";
js.executeScript(script);
After that you can select your anchor or any of the form elements and click or submit it. The target page will open in the same tab.
This basically changes the current HTML page so that anchors and forms don't force the browser to open new tabs or windows. For testing this might be suboptimal, but it simplifies the writing of tests a lot.
Try this out...
Modify FireFox profile parameters "browser.link.open_newwindow.restriction" and "browser.link.open_newwindow".
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.link.open_newwindow.restriction", 0);
profile.setPreference("browser.link.open_newwindow", 1);
If you are using Google Chrome then simply install this extension and it will take care of the rest of the task. This extension is also handy to open pop-ups in new tabs which usually opens in new windows. (First you need to download the extension .crx file from given location.)
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
In the selenium config file:
C:\Python27\Lib\site-packages\selenium\webdriver\firefox\webdriver_prefs.json
change the following line from:
"browser.link.open_newwindow": 2,
to:
"browser.link.open_newwindow": 3,
I test it and it worked
According to Selium docs (https://code.google.com/p/selenium/wiki/FirefoxDriver) the following property webdriver.firefox.profile controls the firefox profile used.
Which is where firefox gets the browser.link.open_newwindow on start up from. To create a new profile for your tests you can follow the instructions here https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles detailed configuration of the profile can be done either by editing the profile's pref.js or firing up the profile and editing it via about:config.
hope this of help!
Actually, Selenium is not responsible of the page opens in a new window or in a same window. It is fully depends upon the Browser settings which you used for execution.
For a sake take Firefox browser
If you want to open all the links in a new window. Do these steps
Open Tools
Click Options
Click Tabs menu
Check the box of Open new windows in a new tab instead.
Now click the link which opens a window. It will opens in a new tab of same window.

Close a newly opened tab or window in Selenium IDE

Using Selenium IDE with Windows7 and Firefox, an automatic click on a link may produce either a new tab or a new window.
close() closes the original window or tab, not the new one. Maybe if I had the ID of the newly created one I could select it and then close it but I don't know how to do this automatically. I've asked on the Selenium forum and read the questions here, but they focus on WebDriver, not the IDE. Any help would be appreciated!
Stig
I had same problem and found a solution:
click on link that opens the new tab
add command waitForPopUp
set focus to new tab via command selectPopUp
make your verifications or other commands regarding to your content in new tab
use command close to close tab
use command selectWindow to set focus to the old window
Screenshot of my Selenium IDE commands:
That works for me.
Use selectWindow(windowID) command to switch to new window in Se IDE. You can select new window by its windowID/name/title.
Hope this helps...
Agreed with surya use selectWindow(windowID), you can get the window title by right click on the page check the option verifyTitle and in front of that you have your Title. Hope it helps out.
selectWindow(windowID) has option to mention title of the webpage/window as a way to identify the target window.
syntax = selectWindow title=My Special Window
note: title = title of webpage that is visisble in webpage's title bar. Or right click on webpage and select menu "Page source". In source doc, select the text between ....
So if the title of webpage = My Special Window, you will see My Special Window.
Hope this will help.
Swasati Paul
You could use the iterator to iterate amongst the windows, close the new window and come back to the originalWindow. And you can put this under the try block because it will only iterate if a new window opens. Or else, it will continue executing normally in the current window.
try{
Set <Strings> ids = driver.getWindowHandles();
Iterator <String> it = ids.iterator();
String currentPage = it.next();
String newPage = it.next();
driver.switchTo().window(newPage);
driver.close(); //it will close the new window and automatically come back to the currentPage
}
finally
{
//continue with your script here
//this script will run regardless of the execution of the execution of the try block
}

VS SDK: ToolWindowPane hides when debugging

I used the VS 2010 SDK to create and show a custom ToolWindowPane with a WPF control as content. I create a new instance and show it each time a Tool menu item is clicked (the ProvideToolWindow attribute has MultiInstances = true).
When the user attaches the debugger (e.g., hits F5 while in C# project) my ToolWindowPane suddenly hides. I'd like to make sure my tool window is always visible while open, no matter what context the user is in. Is there a way I can enforce that?
I've tried using the ProvideToolWindowVisibility attribute but that automatically shows a new instance of my tool window rather than keeping a remaining one open.
For VS 2010 SDK Microsoft added a new flag __VSCREATETOOLWIN2.CTW_fDocumentLikeTool
You can use this way:
public override void OnToolWindowCreated()
{
IVsWindowFrame windowFrame = Frame as IVsWindowFrame;
object varFlags;
windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_CreateToolWinFlags, out varFlags);
int flags = (int)varFlags | (int)__VSCREATETOOLWIN2.CTW_fDocumentLikeTool;
windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_CreateToolWinFlags, flags);
}
This way Tool Window persist open at "Document Well" when you go Debugging
However I have to say this give us some problems when debugging projects, avoiding us to open code files while debugging, like if Visual Studio document management was 'block', there are not so much information for this new flag...
So we preferred to hook to EnvDTE.DebuggerEvents and show the ToolWindow if hide when a debugging session start...
(our ToolWindow has MultiInstances = false)
Implement QueryShowTool
public:
int QueryShowTool(Guid % rguidPersistenceSlot, System::UInt32 dwId, [Runtime::InteropServices::Out] int % pfShowTool);
Enables the VSPackage to control whether to show or hide the tool
window. The shell calls this method when the user switches views or
contexts, for example Design, Debugging, Full Screen.
See https://learn.microsoft.com/en-us/visualstudio/extensibility/opening-a-dynamic-tool-window?view=vs-2017

Resources