Using keyboard input to trigger WebDriver events using Java - java

Im trying to accelerate the use of a web application using selenium Webdriver by creating hotkeys for it. I want certain webdriver click events to be associated with keyboard keys. For example, pressing "s" on the keyboard will click on the submit button.
I understand how to do the clicking and locating elements with webdriver but don't know how to go about listening to the keys from Java while Firefox is open (from a webdriver get call). My application has no GUI and since it's opening a firefox window it will lose focus so KeyListener is not an option.
I have come accross the JNI library that I'm looking into. Any other suggestions how I may do this?

In that case, it is almost always better idea to automate the whole process
Say, you need to daily update salary of the employees. It is better idea to invest your time to read XLS file (almost standard way how those data are delivered to the people destined to do the repetitive work) and read line by line and somehow enter it to the application.
I know I did not provide you the answer you were expecting, but try to think of automating the whole process. It might be little tricky, but doable - and at the end faster - than simple mapping of the keys

Related

Clear Network tab using Selenium Java

I am trying to load a page, and I am automating the process of checking for a POST request after a button is clicked.
In order to do this, I need to clear the Network tab of all previous entries before the button is clicked, otherwise it will not show up on the list for some reason.
Is there a way to do this via logging or some other means in Selenium Java?
As far as I know, there is no way to interact with Chrome's dev tools as you intent to. Alhough, if you are interested in obtaining/parse data from the Network tab in Chrome you can do that following their quick tutorial in their website here.
I don't know what is you idea but here I leave you 2 cents.
Perhaps you could access this data and work it elsewhere instead of constant refreshing.
Here is a similar question to yours.

How to send key-ins to certain windows

I'm looking to write a relatively simple key macro for my own edification and also for my own use.
I intend for it to be able to run in the background when I run other programs, and at the press of a button will enter certain text into the active window. To be more specific, I want to go in a video game and use it to automatically send messages instead of having to type them.
I Googled around a bit, but apparently I'm not using the right keywords because I'm not really sure where to start. The closest I came was finding the Keystroke class, but that appears to be used for receiving keystrokes, not sending them.
I would appreciate and info regarding, or directing me to a resource for, these issues (how to send keystrokes to windows and anything about targeting which window etc).
To send key strokes you can use java.awt.Robot
To Choose which window to activate you can look around for ws script (windows script) or old VB6 code and use it to make VB script (simple text file of extn .vbs)
Or you can junk all that and use http://www.autohotkey.com/ which has window activation, sending keys, doing things on press of certain keys (like Windows Key + B) or macros.
To get a window to activate I had made an exe long back, but no longer use it, can get it from http://sourceforge.net/projects/win-utils/files/Window-Position/rel%2001/ (but only get this if the others do not work as need to seperately get COMCTL32.ocx and install that
If you do not want to use autohotkey you can use Jini to call platform specific functions, with a wrapper to call correst OSes functions. Never done it my self, when i had to use it i would make a process to call a exe that made the window come the front.

file upload in form field for mobile web app

i am developing mobile web app using spring(spring mvc). I need to devlope a form which enables the user to upload file(resume) and on submit it will be stored in database.
I am not getting the idea how to finish that!
In the form when i use input type as file, it's working in diffrent manner on diffrent browser. If any one have did it ,please tell me the steps or some working demo at any site.
yes i don't want to use some third party tool.
thanx.
Sorry dude, your kinda SOL on this one. The file input type is a different beast than most. Each browser implements it in their own way, so it will never look the same on multiple browsers. Also, for security reasons, you can't trigger the file inputs with JavaScript, so you can't make an invisible file input that you would interact with through other standard inputs. Many before you have tried, all have failed. I spent days researching possible alternatives when I had nothing better to do, and they all came up against the security issue. Jquery provides the closest thing but still required a browser switch for one of the major browsers (can't remember which one off the top of my head).
So now that the bad news is out of the way, here's what you can do. Put a button on the screen and style it how you like. Put a file input on the screen and using absolute positioning and a higher z-index put it right over the top of your button. Now make it transparent (not display none, but using opacity and filter:alpha styles), now the user thinks they are interacting with your standard button, but the invisible file input above it intercepts the click. Will be the closes you can get to a file input that behaves and looks the same in all browsers.

how can i make UI automation in java by which i can capture button or menu of any external application dynamically

I want to automate an external application, but I have several problems:
How can I recognize a button or other field of an external application in Java?
I use the Robot class in Java for making notepad automation where I open notepad, select file menu, and save or exit, etc.
The problem is, it needs X,Y coordinates for the mouse pointer to go to the proper location.
I want to make it more dynamic, i.e. it should recognize the file menu of a running notepad anywhere on the desktop.
How can this be done in Java? Is there any class in Java I can use to do this?
Thanks everyone to give me response, I want to be more specific i want to know how can i make ui automation by using any tool if it is not possible in java or using any api of java.automation tool must be freeware.....i am searching net for that i found AutoIt is like that.But if any one do this type of things please share his/her experiance means is it possible to do that in AutoIt or not possible if not then which tool do that kind of things.
It is easy to integrate Sikuli into a Java-application since it is written in Java. Sikuli uses image recognition to find elements visible on the screen like buttons and such. It is very easy to use and provides an alternative for tasks that are difficult to handle with static positioning, like finding moving windows and such.
Take a look at this: http://sikuli.org/docx/faq/030-java-dev.html
Hope this helps!
You should have a look at Sikuli. It takes as inputs images of the ui elements to select an area in the targeted app. It's a UI Automation Application
That's a bit difficult to install (at least on Debian/Ubuntu, where I tested it), as you'll need a recent version of OpenCV, a particular version of JXGrabKey but the quality of the program worth the trip. Good Luck
Java doesn't have an API to examine the UI of another application; that would be a very big security risk.
Which is why the Robot class can only record events (key presses, mouse movements and clicks) but not which UI element was involved in most cases.
It would be possible to do more if the external application was written in Java because then, you could analyze the objects in memory but for obvious reasons, this isn't possible for C++ or .NET applications.

Block all other input to an application and control it from a wrapper in Java

I have a windows application which has a complex GUI that I would like to hide from users. In order to do this, I would like to create a wrapper with an extremely simple interface that overlays this application and automates a number of actions when a user clicks a single button on the wrapper. (I hope "wrapper" is the proper term.) Is it possible to use Java to block input to the underlying application so that users cannot inadvertently mess up the automation? How would I go about this? Also, how can I automate key presses and clicks to the application without hijacking the mouse? Is this possible in Java?
I have looked at java.awt.Robot, but it appears to hijack the mouse.
I have also looked at AutoIT, but it too hijacks the mouse and does not integrate with Java.
Neither of these options seem powerful enough for what I need, but I do not know how else to proceed.
I recommend that automation via the GUI only as the last resort if you really have no other alternative.
If there is an API that your application exposes, I would try to use that. For example, if the GUI is implemented in one DLL and the logic in another, then you can use JNA to load your application logic DLL and invoke the application functions directly from java. Even better would be if your application exposes a COM/OLE interface - there are plenty of Java<>COM briges, that will alow you to call this interface directly, e.g. Jacob.
If you really have no choice but to automate via the GUI, then here's how to go about doing that:
Use JNA to access the windows shell API. You can then use ShellExecute to launch your wrapped application. Specifically, passing SW_HIDE as the window mode should help ensure that the application does not appear.
Use JNA to access the windows API FindWindow to find your application window. You can also make it invisible using the ShowWindow API, just in case step 1 did not work (not all applications are written to use the nCmdShow parameter.)
You can now post messages to the application window using PostMessage. You can send keystrokes and mouse events using windows messages. E.g. See WM_KEYUP, WM_LBUTTONDOWN.
Because the wrapped application window is made invisible, you don't need to "block" that application, The user simply cannot access it's GUI. But you can still programmatically send input to it.

Categories

Resources