Unable to Rename Window Title Text Via SetWindowText Function - process

I am using SetWindowText Function to rename Window Title it seems to work with Windows program like "notepad" but when trying with other 3rd party program its not working.I am grabbing window handle via Process..MainWindowHandle . I want to spawn firefox and rename its window title this is my requirement.Process is getting launched but Window Title rename is not happening i am getting "Send Error Report" Dialog window.Please Help me out.Below is the code.
using System;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;
namespace SampleNamespace
{
public class SampleClass
{
[DllImport("user32.dll")]
static extern int SetWindowText(IntPtr hWnd, string text);
public static void Main()
{
Process p = Process.Start("C:\\Sham\\pg\\Firefox\\firefox.exe");
Thread.Sleep(1000);
SetWindowText(p.MainWindowHandle, "FireFox via Process-Start");
} // End of Main function (program statup)
}
}

Many programs set their main window titles repeatedly during their execution.
A good example is Firefox which changes its main window title whenever you browse to a new page. Likewise Notepad will change its main window title whenever you open or save a file to include the name of the latest file.
The only way you can realistically expect to exert control like this is to poll.

The problem may occur because Firefox, google, IE work in few processes to isolate different pages from each other, so if one tab crashes, the other will still alive. Open Windows Task Manager to ensure. (Opera is still dont but thes feature is already planned for future releases).
Possible solution for you is to enumerate all processes with name 'firefox.exe' for instance and change window titles of windows that match some of your criteria.

Related

Sending automated text messages from web.skype.com, using Selenium

I’m trying to send automated text messages from Skype web client, using Selenium.
So far, I was able to authenticate myself and select the required unique recipient. It works fine both programmatically (Java bindings) and using Selenium IDE.
But I was not able to successfully add text to the message box. And without that, Skype does not even shows the send button!
In a recent past, I googled that one could send a message with something like:
input_messages = browser.find_element_by_name('messageInput')
input_messages.send_keys('Testing Output' + Keys.RETURN)
But I guess Microsoft changed the web client as this does not work anymore, namely by not showing the “Send” button unless something is written in the message box:
Using Selenium IDE, it records this set of commands (Skype authentication omitted):
However, running above script, I get what seems to be an overlapped “Test” string on top of original “Type a message”:
It seems obvious to me that Selenium IDE is not placing my “Test” string in the “right” place. And because of that, not even the send button is shown.
Here’s the “edit content” parameters:
Target
css=.notranslate
xpath=//div[2]/div[2]/div/div/div/div/div/div/div/div[2]/div/div/div/div[2]/div/div/div
Value
<div data-contents="true"><div class="" data-block="true" data-editor="f244q" data-offset-key="0-0-0"><div data-offset-key="0-0-0" class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr"><span data-offset-key="0-0-0"><span data-text="true">Test</span></span></div></div></div>
And the Chrome Inspect of the message box:
So, any idea what Selenium IDE (or myself…) is doing wrong?...
What is the right locator and how to edit its content (to set my text message), making sure the send button is then shown and clickable (though a Keys.ENTER should then suffice).
Thank you in advance!
Windows 10 - 1903 (64-bit)
Google Chrome 85.0.4183.102 (Official Build) (64-bit)
Selenium IDE 3.17.0
chromedriver_win32-85.0.4183.87
selenium-server-standalone-3.141.59.jar
I have encountered similar problems and tried many methods:
clear the element before sendkeys
sendkeys multiple times in for-loop
I can’t tell which method is effective, so I will give you a code snippet in my real project.
// for the div element
boolean bl = false;
for (int i = 0; i < 3; i++) {
element.clear();
element.sendKeys(text);
if (element.getText().equals(text)) {
bl = true;
break;
}
}

Controlling level and focus of windows other apps with CGPrivate functions

Question
How to use these private functions on other windows? It would be nice to have this knowledge back in the wild. I am specifically trying to get CGSOrderWindow and CGSSetWindowLevel to work.
I was trying in the direction of:
temporarily register as the dock and then register the dock as the dock again immediately afterwards
or
code injection into the Dock process per this comment:
Also, the author of the above project seems determined to make all core functionality available as a framework. It seems to be implemented as code injection into the Dock process.
Reason I know this is possible
I have been doing work on trying to setLevel on window of another app, and focus window of another app if focused. I am posting this again with the info I learned because from my searching online, I know this was done in the past, its just the knowledge is not publicly out there anymore. The sourceforge pages are no longer there. So I was wondering if you could help me make this information public again.
This is the topic I read that gave me this information - http://cocoadev.com/HowtoControlOtherAppsWindows
Here you see comments like:
You cannot control an another app's windows from a user-level process, unfortunately.
SlavaKarpenko
You can, Slava, you just need to register as the Dock. It might be possible to temporarily register as the dock and then register the dock as the dock again immediately afterwards, not sure. I think the call you'd be wanting to investigate as CoreDockRegisterDockOwner in HIServices.framework.
FinlayDobbie
You could also use APE or similar to do control the windows, or (as mentioned above) register as the Dock (look for the private APIs with Universal Connection in their name). Has anyone found a polite way of getting the Dock to give up its universal connection? The only way I can find is to force quit the Dock and grab the universal connection when it's not looking (which prevents the dock reloading).
SamTaylor
There's an open source project up on sourceforge.net that looks much more like the window managers I've used on Unix boxes than Space.app (or Space.dock): http://wsmanager.sourceforge.net/
SteveCook
Verifying things work
This is what I learned, from the sources at bottom of this post, we see all these functions work with CGWindowIds, so how do I get that, this is how:
Get all windows with CGWindowListCopyWindowInfo. Then access each element from that array with CFArrayGetValueAtIndex and then get the CGWindowId with objectForKey:, kCGWindowNumber, and then integerValue.
Now if I try to focus or set level of a window that is OWNED by the app running the code, it works fantastic. For instance:
MY_TARGET_CGWINDOW_ID = 179;
rez_CGError = CGSOrderWindow(_CGSDefaultConnection, MY_TARGET_CGWINDOW_ID, kCGSOrderAbove, 0);
Will focus it, rez_CGError is 0. Even if the window is minimized, it is unminimized, without animation, and shown.
Now however, if I try this on a window of a different app we get some errors:
MY_TARGET_CGWINDOW_ID_of_other_app = 40;
rez_CGError = CGSOrderWindow(_CGSDefaultConnection, MY_TARGET_CGWINDOW_ID_of_other_app, kCGSOrderAbove, 0);
This fails and rez_CGError is 1000, which I suspect means "cid (CGSConnection) used does not have permission to modify target window". The same happens if I first do [app activateWithOptions: (NSApplicationActivateIgnoringOtherApps | NSApplicationActivateAllWindows)] before making the call above.
So I first get the cid of that owning window like this:
var rez_CGError = CGSGetWindowOwner(_CGSDefaultConnection, MY_TARGET_CGWINDOW_ID_of_other_app, &ownerCid);
This works good and I get ownerCid is set to a value. Then I do the focus command with this new connection:
rez_CGError = CGSOrderWindow(ownerCid, MY_TARGET_CGWINDOW_ID_of_other_app, kCGSOrderAbove, 0);
However this gives rez_CGError of 268435459, which I suspect means "current app does not have permission to use this ConnectionId (cid)". (Same happens if I call activateWithOptions first.
My Sources for the Private Functions
Here is the sources for some private functions I found - https://code.google.com/p/undocumented-goodness/source/browse/trunk/CoreGraphics/CGSPrivate.h
This one source here contains a function that is not in the above link - CGSGetConnectionIDForPSN - i test it and it exists - from - https://github.com/mnutt/libqxt/blob/767498816dfa1742a6f3aee787281745afec11b8/src/gui/qxtwindowsystem_mac.h#L80

How do I interact with a popup window with Mink, Selenium 2, and Behat?

I am running through an internal site with Behat and for the most part it is going really well. But the problem is that on certain parts of the site we have popup windows that come up to complete an action. In this case we hit a "Withdraw" button and a popup comes up to have you select a reason and save it.
In an ideal world, and if I had actually designed this app, the site wouldn't be using any popup windows. But I am the new guy who is supposed to implement automated functional tests (and I am learning how to do that from the ground up). So I don't really have any say over the site design at this point (though I will push for a lot of changes as time goes by).
I am running Behat with Mink and the Selenium 2 driver on an Ubuntu 12.10 system (will eventually have to run some tests on a Windows environment for testing in IE). I am also using PhantomJS for some of the tests I have setup.
Anyway, does Behat/Mink support working with popup windows somehow through the Selenium 2 driver (or through PhantomJS)? I am early in all of this automation setup and really I am just experimenting with tools. If there is a better tool that can handle this then please let me know.
My primary question is how do I get Behat/Mink to work with the popup window, check a box, fill in a field, and click the save button? I know how to do everything except get it to interact directly with the newly popped up window. Any ideas/suggestions would be welcome.
Thanks!
So it turns out that Mink includes some window switching features, but no way to identify said windows. So I wrote two functions getWindowName() and getWindowNames() that identify the current window and all open windows respectively. I committed these changes to the project in GitHub it seems that my fixes will get implemented soon into the code base.
But with these changes I am able to switch windows no problem.
Link: https://github.com/Behat/Mink/pull/341
By setting the focus of the window we can also name these windows so we can access them again in the future.
Using this method we can easily switch between popup windows and continue testing...
/**
* #Then I switch to popup :name
*
* #param $name
*/
public function iSwitchToPopup($name)
{
$this->iSetMainWindowName();
$this->getSession()->switchToWindow($name);
}
/**
* #Then I set main window name
*/
public function iSetMainWindowName()
{
$window_name = 'main_window';
$script = 'window.name = "' . $window_name . '"';
$this->getSession()->executeScript($script);
}
/**
* #Then I switch back to main window
*/
public function iSwitchBackToMainWindow()
{
$this->getSession()->switchToWindow('main_window');
}

Launching RDP (mstsc.exe) with a supplied IP without autoconnecting

I am creating a program (in C#, .net 4) that allows the user to highlight an IP address from a textbox and click a button that launches RDP (MSTSC.EXE) supplied with the highlighted IP. What I'd like to do is NOT have RDP try to auto-connect to the IP (which is what happens if you provide the -v: argument). Rather, bring up the usual RDP dialog that will allow the user to either edit the IP or click "Connect" to go ahead and connect.
Is this possible? There doesn't appear to be any command line switch that prevents autoconnecting. The only thing I can think of is to create an .RDP file with the IP and then use the -edit switch. Although I'm wondering if it's possible to launch mstsc.exe and then do some kind of Clipboard paste to paste the IP into mstsc.exe?
Found the answer after rewording my question.
SendKeys.SendWait("^V") did the trick.
To avoid reconnection see this link
For the rest use
using System;
using System.Diagnostics;
using System.ComponentModel;
namespace MyProcessSample
{
class MyProcess
{
static void Main()
{
// Get the path that stores favorite links.
Process.Start("mstsc.exe", "/v:10.58.45.24"); //Or whatever
}
}
}

How to emulate mouse click using wxWidgets

Is there any function in wxWidgets framework, say, click(), whose function is to emulate a left-click mouse?
No, there is no function like this. If you really need to do it, e.g. because you want to perform some action in another application you need to write platform-specific code yourself (e.g. use SendInput() under Windows).
If you want to use this to execute some code in your own application though, there is a much better solution: instead of doing unsupported, fragile and ugly
void MyClass::OnLeftUp(wxMouseEvent& event)
{
... do something with click at event.GetPosition() ...
}
void MyOtherFunction()
{
wxMouseEvent event(...);
... initialization not shown because there is no right way to do it anyhow ...
myObject->ProcessEvent(event);
}
just refactor your code to do it like this instead:
void MyClass::OnLeftUp(wxMouseEvent& event)
{
HandleClick(event.GetPosition());
}
void MyClass::HandleClick(const wxPoint& pos)
{
... do something with click at pos ...
}
void MyOtherFunction()
{
myObject->HandleClick(position);
}
If you're just talking about emulating a click on another button in your wxWidgets app, I've tried this before:
Create a fake wxEvent of the right type, tell the event what object to care
about using SetEventObject(), and tell a parent wxWindow in the hierarchy to
ProcessEvent(myNewEvent). You might want to use wxGetTopLevelParent() to get the topmost frame/dialog
If you are talking about emulating a click in another, non-wxWidgets process, it's possible you could use the OS's accessibility APIs to do this. wxAccessibility should be able to help with this on Windows -- for other OSes, last I heard (granted, a few years ago), you'll have to use the native OS functions.
You can use the wxControl::Command() method. According to Documentation:
Simulates the effect of the user issuing a command to the item.
Documentation page
List of events to use with wxCommandEvent constructor
You can simulate a click on a button like this:
$this->MyButton->Command(new wxCommandEvent(wxEVT_COMMAND_BUTTON_CLICKED));
There is also the wxUIActionSimulator class that you can use to simulate UI actions.