Java : Take screenshot of visible area in the browser - java

Is there a way to take the screenshot of the display in a browser in Java minus the browser window. The flow is :
Load the webpage in a browser. Then make an AJAX call to a Java service which captures the screenshot using the code from : How to take a screenshot in Java? .
The problem here is that I only want to capture the visible area in the browser excluding the browser window, the windows task bar and the other unwanted stuff.
Thanks

You can just measure how big is the displayable area and capture that section only.
As for the AJAX call to a Java service part is not posible.

As #OscarRyz already mentioned AJAX call is irrelevant here.
You have to create java applet that calls new Robot().checkScreenCaptureAllowed(). This will capture whole screen.
The problem is how to understand where the visible area is. You can probably do it. You have to create at least one visible element in your applet. This element could be even very small (e.g. one pixel), so user will not see it. Then you can invoke getLocationOnScreen() that gives you the absolute coordinate on screen. If your java applet is in the top-left corner this is the point where your visible area starts.
JavaScript allows you to know the height and width of current window: window.innerWidht and window.innerHeight. So, you now you can take your screen capture and cut the area that you need.
But please take into consideration that new Robot().checkScreenCaptureAllowed() checks READ_DISPLAY_PIXELS_PERMISSION and I do not believe you have such permissions for unsigned applet, so you will have to sign your applet.
To avoid this problem take a look on this: http://html2canvas.hertzen.com/ - script that "captures" screen and uses JavaScript only.

Related

Rendering graphical elements through command line interface in Java

Is there a way to render graphical objects in console using standard jdk API?
For instance I want to render moving image in console (not via awt/swing).
The console itself can only render characters..
But if you mean you want to render an image from a command line app. (that is later displayed in other apps.) then yes, though the 'moving' part does not make much sense unless you mean an animated GIF.
No you cannot. The console renders characters so ASCII-art is your best choice.
Also this has been answered before: displaying-images-in-a-console-application

Jumping from screen A((Web Page) to Screen B(Web Page) bypassing intermediate screens(Web Pages) using selenium webdriver

This question is not about window handling or juggling of multiple browser windows, its about navigating through web pages of a web application within same window.
I have a situation where
1.I navigate as screen A->Screen x->Screen Y-> Screen B
2.I need to capture certain parameters on screen B from First login
3.I need to verify those parameters on screen B from second login
Here what i wish to do is to avoid the non important task of navigating through intermediate screens & jump directly to the concerned screen. Or directly capture the concerned parameter without bothering about UI.
Note- The URL on this application window is non editable manually.
Example-
Login->Jump to Screen B(First Login)
Login->Jump to Screen B(Second Login)
Firsts of all, is it possible at all??
Please help me with the suggestions of how to achieve this
Additional Detail-
URL to view a project named Selenium Test 275 (A specific web page in the application) is ->
http://172.24.186.71/esssfa/sfanew/UnitList.aspx?OID=12762&PID=12731&PRID=1&SecID=3
Edit:
I think I understand what your asking now. If you want to easily jump back a few pages, to that spefic screen B, I would use JavaScript.
(-1) will get the last page that was on your browsers stack. (-2) two pages, and (2) will then make the browser get two pages forward on the browser.
If you want to go back to Screen B try something like this after logging in.
driver.execute_script("window.history.go(-2)")
Then a variable can be used to store the data from the last login that you want to compare.
Possibly that the second window opens based on response from the server?
For e.g - the server could be returning a URI along with a session/security attribute(JSESSIONID, Authorization, etc) which is then appended with base URI to open up the new window. The session/security attribute explains the invalid session page message when you try to driver.get(URL) of the second page.
At the risk of being repetitive (rephrasing Vivek's question) - are you able to open the second screen in this way :
Login to the application (first screen) -> Open a fresh browser window -> Paste the (read-only) URL of the second screen and hit Enter -> Check second screen opens.
If yes, then it seems to be a case where it is not just simple GET request but possibly a request with some sort of Authorization code in the request headers.
Additional details might help answer your question : is it possible ?!

Getting pixel position of a text in an image

I am working on a research project.The scenario is this.
I am taking the screenshot of my desktop and then I process it using an API to get the position of a certain text on my Desktop.e.g , say I have the browser open on my desktop and I am on stackoverflow.Now I want to search the position of the logo stackoverflow on the screenshot taken.Then I want to simulate a click on it.I am using Java platform.
Now I have 2 questions:
1)Is there any free API(OCR) which I can use to process the screenshot to fetch text position (or can be done by some trick) and gives good results.
Or Any way you can suggest that I can use (instead of taking screenshot and processing it) to get the position of any text on the screen.
2)How can I simulate the click on the screen using the code by a background program running(I mean I have done it in Swing and other language UIs but this time its different as Now I want to click on the screen.
If I understood you right you want to move your mouse and click on the screen. That not that hard you could use the robot class from Java!
For example:
Robot rob = new Robot();
rob.keyPress( KeyEvent.VK_ENTER );
or what ever, there are so much bottons and movements you could with it. A list of all methods you find here.
And your other question I can't answer. I think there is no API that is able to search a text and give you the position. But what I know is that the robot class is able to capture the screen and put it into a BufferedImage. With it you could compare two pictures.
Maybe you could get use of this but I don't know if it is what you search.

How to display clickable hyperlink in Papplet Java application?

I know how to display simple text with the processing.core.PApplet.text method.
But this one can't display clickable hypertext link. How could I make that in Papplet ?
I precise that link should open the web browser.
Thanks.
It's not documented on the main Reference page at http://processing.org/reference/, but you can use a function called 'link()' ... it takes up to two parameters - the url to go to, and if the second argument is supplied, sets whether to open a new page or not...
Eg.
link("http://www.processing.org", "_new");

Signature capture on windows mobile java application

The company I work for has an java application that runs on esmertec jbed JVM on windows mobile 6.
There is a requirement to capture a user's signature as part of some new functionality. One option is to try and implement this in java. This has been tried previously and has been found to be a bit slow.
I think the better option would be to get a native component to handle the drawing of the signature and save it to file. Does anyone know of a component that I would be able to use?
Creating our own component is an option as well but if there is one available already, I would prefer to use that.
For completeness, I'll answer my own question.
I could not find an existing component that done this. We ended up writing some c++ code that would handle this.
The code would get a handle to the Java canvas and register our own callback function with it. This callback function would record any mouse movement within the canvas and draw a line when necessary (either on mouse up or after a number of points had been drawn). Once the user leaves the screen we would save the canvas to file and re-register the original canvas callback function.

Categories

Resources