Java - Get title of active window - java

I need to get title of current active window(for example right now: Google Chrome). I search smth in internet, and found only this javax.swing.FocusManager.getCurrentManager().getActiveWindow(); . But i don't know how to get PROGRAM TITLE with that code.

If you are fine with a non-java solution that will work for Windows computers, there is a programming language called AutoHotkey (AHK) that is more suited for this kind of task. There exists a popular script called "Window Spy" (also known as "ActiveWindowInfo") that has the ability to view the title of the active window, as well as other information such as PID, the name of the .exe that the Window is an instance of, and etc. (I have attached a screenshot of what Window Spy told about the Google Chrome window I was using to write this reply. In the screenshot, I have also indicated which part of it tells you the Title of the Window).
This script comes with most AutoHotkey IDEs (such as SciTe4Autohotkey if you are interested). However, you can perfectly well run the script without an IDE.
Here are some quickstart instructions:
First, you will need to install AHK itself (here is the official website)
You can download the script itself by navigating to https://raw.githubusercontent.com/fincs/SciTE4AutoHotkey/master/source/tools/ActiveWindowInfo.ahk in Chrome, using the shortcut Control+S to save the script to your computer. Make sure that when you download the script, it ends with a .ahk instead of the .txt that it will default to.
Navigate to the file that you downloaded and run it with AutoHotkey (It should be the default thing that happens if you double click the .ahk file with AutoHotkey installed).
If you need any more info on how to use the script, please let me know.

Related

Opening zoom meetings from Java

I'm trying to create a Java application which will be able to open (join) Zoom meetings.
You can open zoom meetings via terminal if you explicitly have id and password, with command: open zoommtg://zoom.us/join?confno=ID&pwd=PASSWORD, you can use this command in Java as well.
However, sometimes you don't own the id and password explicitly, you have some strange link, with no way to evaluate their id and pass. Though, if you paste this strange link in say Google Chrome, it will offer you to launch Zoom application and then you will join the meeting.
I can do this with Java, I can make default browser go to some link, but I don't want that, I don't want to go through browser, I want it directly.
Is there any way to open Zoom meeting directly from Java with just strange link? (No id and pass explicitly) As Google chrome does it, it has the link and it's able to open the meeting.
Well, if I could open it via terminal, I would do it with Java as well. I tried curl, but it's just getting me the html response only, maybe expected.
By the way, if needed, I'm using MacOS Monterey with zsh.

Downloading Files with ChromeDriver

I have a project where I need to download an audio file in ChromeDriver. The behavior here is different from in regular Chrome, where if I visit the URL, it'll automatically start downloading a file. If I do the same thing manually in ChromeDriver, it will not download the file.
I've tried different configurations of the chrome options/preferences. I've also found options that worked with old versions of chrome, that no longer work anymore.
Here is one of the better resources I found, but it still didn't work, even with their updated blog post
https://dkage.wordpress.com/2012/03/10/mid-air-trick-make-selenium-download-files/
When I attempt to use his solution, my chromedriver abruptly crashes itself in a non chrome-esque way. It just disappears. Not "Something went wrong" page like you'd normally expect. I end up with Java not being able to find my Session, cause it stopped existing.
Has anyone been successful at downloading files through Selenium webdriver in Chrome? If I need to use another browser, I can.
I'm currently using Chrome Canary.
I have the same problem. One solution that might work is to use another library, that is able to operate outside of the browser. I found these stackoverflow post discussiong this issue:
https://sqa.stackexchange.com/questions/2197/how-to-download-a-file-using-seleniums-webdriver
it contains this blogpost wich gives you some sugestions.
https://blog.codecentric.de/en/2010/07/file-downloads-with-selenium-mission-impossible/
Window automation
The first approach smells like “brute force”: when searching the net for a solution to the problem, you easily end up with suggestions, to control the native window with some window automation software like AutoIt. Means you have to prepare AutoIt such, that it waits for any browser download dialog, the point at which Selenium is giving up, takes control of the window, saves the file, and closes the window. After that Selenium can continue as usual.
This might eventually work, but I found it to be techical overkill. And as it turned out, there was a much simpler solution to the problem.
Change the browsers default behaviour
The second possibility is to change the default behaviour of the browser. When clicking on a PDF for example, the browser should not open a dialog and ask the user what to do with the file, but rather save it without comments and questions in a predefined directory. To accomplish that, a file download has to be initiated manually, saved to disk and marked as the default behaviour for these file types from now on.
Well, that could work. You “only” have to assure that all developers, hudson instances, etc. share the same browser profile. And depending on the amount of different file types, that could be some manual work.
Direct download
Taking a step back, why do we want to download the file with Selenium in the first place? Wouldn’t it be much cooler, to download the file without Selenium, but rather with wget? You would have solved the second problem as you go. Seems a good idea, since wget is not only available for Linux but also for Windows.
Problem solved? Not quite: what about files, that are not freely accessible? What, when I first need to create some state with Selenium in order to access a generated file? The solution seems ok for public files, but is not applicable for all situations.

Changin syscalls global (temporarily?)

I have installed a software (java application - not my own, No sourcecode available!) which opens the browser (specific link) after pressing a button. Is it possible to change that behaviour to just "copy the link to clipboard"?
Maybe a global sys call modification? The problem: i dont know anything about hooks, syscalls etc. but i know that the program is opening the process "run32dll.exe" and uses the api "shellexecuteA(URL)"
Is there a way to do this?

How to check (on website) if Java is installed on system (*not* in browser)

I have a Java desktop application, and a website where users can download the .jar file.
I would like to have a button on the website that the user can click to check if the application will run on his computer (i.e. does he have the correct version of Java installed on his system).
Please note that I am not trying to check if Java is enabled in the browser (as deployJava.js will do), but instead to check if it is installed on his system.
My users are not very tech-savvy, and I hope to make this as easy as possible.
Thanks for your help.
There is no way to do this via JavaScript. A better solution would be to use a system specific jar launcher that checks if Java is installed and then either installs/launches the java prorgam or outputs an error message.

How to enable MSIE8 in 'Default Java for browsers'?

I'm using IE 8.0.7600.16385 for testing (the default browser is FF) an applet.
The applet is part of a project to deliver music off CD & DVD (it is an MP3 player).
It was working around a month ago (or so), but when the page is loaded from
local disk now, it does not pop the Java Console (which is configured to open
automatically for applets and JWS apps.), & does not load the applet. Instead it
puts a little icon in the upper left of the space the applet should be
that looks like below (the red arrow points to the icon).
Clicking the icon and everywhere else around the applet space produced no further information.
After trawling through the IE options, particularly under the Security, Content & Advanced tabs
and setting all the options I thought might help (to no avail), I opened the Java Control Panel
to see..
So it seems that something in Java itself is stopping IE from loading applets.
How do I reconfigure Java to enable the IE listing under 'Default Java for browsers'?
Update 1
IE will happily load the applet shown at Property Probe (a sand-boxed applet on my site). While another tab of the browser will fail to (attempt to load and) render the applet off the local file system. I am tending towards putting this down to something that changed in IE, though I cannot see how it could have changed between the old and recent tests. The JCP is still showing the IE entry grayed out, which suggests that is its way of indicating that IE is not the default browser (?).
I also noticed that a similar version of IE on the Netbook fails to load the applet off disk with the same symptoms. :(
Update 2
The problem applet is load into a frame (yeah sure, 'ick frames!' get over it) using deployJava.js - a script supplied by Oracle to do version checking before running an applet.
A plain applet in unframed HTML will load just fine off the local file system. I'll do further tests to narrow it down to the 'frames' or the script. But I am betting it will be the script that triggers this behavior.
deployJava.js is the deciding factor. An applet in:
framed HTML
loaded off the local file system
..works in IE8 - unless it is
embedded using the script.
Since I have other ways to do what was needed from the script (plug-in version checking), I'll remove the script and use the alternate method.
And to answer the question as to why the behavior in IE 8 changed. Last time it was tested in IE, the applet element was hard coded in the HTML, no script or version checking used. :P

Categories