How to use Java code and Sikuli to click menu items - java

I have an application where I need to be able to log out and the only way to do so is to click on the Log out option in the drop down menu however I am having a lot of problems.
I have captured the screenshots using the Sikuli IDE and when I run my code from the IDE it works perfectly fine. (The code clicks on Menu and then Log out)
However when I try to run the code from Java it appears that it selects Menu and then when it tries to click Log out, the menu disappears.
My guess is that for some reason Java is putting the focus on the mouse before it moves to the Log out button and when the focus goes to the mouse the menu disappears as it does when you click elsewhere.
I have also tried making Sikuli press the down button several times to get to log out but the same thing happens when it tries: the menu disappears.`
This is my Java code. The Sikuli code has the same two click commands:
#Override
public void logout()
{
click("loggedInIndicator.png");
click("logoutButton.png");
}
Please help! There is no other way to log out that I can find.

I suggest you to print the image Sikuli finds to be the best match for the elements. My guess is it selects a part of the screen that has nothing to do with the element you want to click on, making the menu disappear.
Match element = region.find("loggedInIndicator.png")
Screen screen = element.getScreen()
String imagePath = screen.capture(element)
This saves an image of the element found by Sikuli in the System temp directory. As it is a temporary file, you'll certainly have to move the freshly created image file to another directory so that it'll not be deleted immediately. I found this happening several times on Windows

Related

Netbeans re-open (Java) file at last viewed position

Netbeans always opens (Java) files from the top. However, I want to open them at the last viewed position because it is likely that I have to continue editing near this position (see also Locality of reference). Furthermore, it makes sense to continue navigation at this place because it is where I left and so I have this relatively fresh in my mind. Thus, it gives me orientation. Finding the last viewed position can be time consuming.
Some other editors, e.g., Visual Studio Code show the last viewed position when opening a file. This little change helps me a lot to navigate and edit code in re-opened files. I once asked the same for Eclipse but now I have to use Netbeans.
Similar behaviour can be observed in modern browsers. Scroll down a page, close the tab, reopen the tab from the history. The page will be opened on the same scroll position where you have left.
Is it possible to get the same behavior in Netbeans, i.e., re-open files at the last viewed position? I am using Netbeans 11.2.
Steps to reproduce in Netbeans:
Open a file, scroll down in that file and select some text, close the file, click on "file > open recent file > [THE FILE]" in the menu bar.
Now, the selection and scroll pos is gone but I want to continue where I have left the file.

Detect open folder in Java (JNativeHook)

I'm using JNativeHook to detect drags and clicks outside a JFrame in my program and it's running perfectly. The thing is I need a way (either using JNativeHook or anything else) to check if a folder is opened in my explorer (Finder for Mac) so that I can move a file to this opened folder. JNativeHook doesn't seem to have the option of detecting on what program or window was the click made.
I expect the output of the code I'm looking for to return the path of open folders in my system explorer so that I can move files to this path.
You will not be able to detect if explorer is opened to a particular folder. There are API's to detect things like the window under the cursor and get information like the title, however, if explorer is not displaying the path in the title, it will be very hard to detect without traversing the application components and finding the address bar of the window. See WindowFromPoint and GetWindowTextA for a staring point. It should work fine under JNA and can be combined with the coordinates returned from JNativeHook.

building many programs that are managed by a parent program, looking like it's just one program

I want to make a launcher type program which will allow me to launch other programs I made... not sure how to go about that...
The launcher needs to start/show the children programs when their button is clicked and make it seem like it's one single program, they will have similar layouts. When the launcher window is moved around, the child moves around with it...
I was thinking about having the launcher start the other programs (java -jar) when the respective button was clicked and passing arguments to tell the child program where to position it's window so it looks like it's just one program, which would probably work until that point... but when the user clicks away from the window, it needs to hide together with the launcher, but next time the button for that program is clicked, it should just continue where it left off, show the window...
I hope I explained that well...
I just need some hints about what to look into...

SWT Menu unresponsive on MAC

I was trying out example of how to create Menu using SWT. I am using Eclipse on Mac. I was referring to this example. Whenever I run this example, I have two problems:
The Menu doesn't show up until I make it full screen.
The Menu buttons are unresponsive i.e when I click on Help, it doesn't show up the dropdown containing Get Help.
Do I have to make some spwcific changes while creating Menus on Mac?
Probably 7 years too late, but if anybody finds this I had the same problem and I simply switch to another window and switch back to the display and it worked. I don't know why it works but it did it for me and I hope it will for you as well.

changes not upadated in eclipse

I am writing a simple registration form in html using Eclipse Indigo.But after running one time on server Apache Tomcat 6.0 ,it is giving perfect output.But later if i am trying to modify any value in html form then it is not updating in resulting browser output
Press "Republish" button on the "Servers" view in your Eclipse window.
I report a similar fact and its solution: fantasy names for files. Eclipse Neon. I create: Red.html with code for a red button and Green.html with code for a green button. I choose Google browser from Eclipse ide and display correctly both html. Then I destroy, from Eclipse ide, Red.html and rename Green.html to Red.html. I launch the renamed Red.html and I see a red button instead than a green one. I open Google settings, and cancel navigation data from the last hour. Now Red.html displays green button. I've done so, because Internet Explorer, not involved in previous manouvres works right: present Red.html displays green button. I haven't tried the ide way as in the previous answer, as I'm new to Eclipse. I tried the browser side with caution: only 1 hour of navigation.

Categories

Resources