Is there a way to copy text from a browser to my Java app ?
For example, at the left side of my screen I open a browser to point to a URL and shows the content of that page, it might be in a frame or CSS or simple html, on the right side of the screen I open a Java Swing application. I'm interested in certain parts of the browser window that shows some text, and I want my Java app [ without me doing anything ] to copy and paste the text into itself, can it be done ?
I know I can use JEditorPane or JTextPane and set it with an HTMLEditorKit, then load the text into the pane, but if the page uses Frames or some other complex ways, the text I get from the Pane is not what I see on the page, so I don't want to do it by loading the URL into my Java app, instead, I wonder if it can be done in the way I mentioned above ?
I think you're looking at the problem from the wrong angle. If what you want is to harvest a website, I suggest you have a look at the awesome library web-harvest. With a little Xpath wizardry you can get everything you want.
Doing what you describe would imply inter-process communication that seems like an overkill. There are more ways to download a web-page content than the browser.
You may try the following depending on your needs.
With java.awt.Robot you can either 1) Take an screenshot if what you neeed is the content ( without the text, just an image of the browser content ) or 2) Move your self into the browser and programatically press: CTRL-A + CTRL-C and return back to your swing app focus and programatically press: CTRL-V ( or CMD or whatever makes sense in your OS )
But again, this might or not work, depending on what you need.
I know a tool but i am not sure it meet your needs. Have you heard about selenium? http://seleniumhq.org/ It can replicate actions taken by the user in a browser and then manipulate them ussing java code. Have a look at the link it may be handy.
Using java.awt.Robot & a TextField will get the job done, not sure if there is any other way. Have robot press ctrl+a then ctrl+c, bring TextField into focus, and finally have robot press ctrl+v. Now from here you can create a button.setOnAction to save the TextField text into a string. Or you can use a change listener on the TextField setOnKeyReleased to do the same.
Related
Well I need to show text messages directly on the screen.
I tried searching a lot but found nothing that could solve my problem.
The options I found on the interner:
To use a JFrame and render text on that.
To print text on a console.
But the problems with these here I do not want any window to pop up.
I also want the text to be on top of all.
My attempt:
As far as my tries here it is :
Here is what it should look like:
As you can see my try is far from what I want.
Well is there a better way? Is it possible Without any Frames?
Well this could be similar to Toast messages in Android.
I did achieve what I intended.
Here is the link to the GitHub Repository : https://github.com/Jaysmitio101/jsubs
This is a Java Library for showing subtitles on any screen and also show messages like Toast messages in android.
I have searched for similar questions and I didn't find any talking about this.
We have a JavaFX application where the main content is a WebView. We want to allow screen readers to detect and read the content, but it seems to be broken.
Screen readers like NV Access and VoiceOver detect and read the frame, buttons and everything outside the WebView but not the HTML content.
Is there any limitation that explains why screen readers can't access the web page? Is there any way to allow it?
I've run into this same issue. I have a workaround idea that works like this:
On the relevant html elements that I want to read, add an onfocus() handler that calls up through the JavaScript bridge and passes up the text that I want the screen reader to read to a java method e.g. readText(text).
In readText(text), create a Swing element, e.g. a JLabel, and add the "text" to the accessible description of the JLabel and then manually trigger the screen reader to read "text".
However, I can't get the "manually trigger the screen reader to read" step to work. I've been studying the Java Accessibility Utilities documentation but can't find anything that works. Does anyone know if this is possible?
How can I, in an Applet, get the Window containing the Applet as an Window Object?
My goal is to make a screenshot of the content of a "Website".
I tried to make this with the Robot object:
Window window = ???
BufferedImage bufferedImage = new Robot().createScreenCapture(window.getBorder());
To get the border of the browser is the reason why I need this as a window object.
Or is they another possibility to do this?
To get the border of the browser is the reason why I need this as a window object.
Figure how to do it in JavaScript. Call the JavaScript from the applet.
This might not be the only way to do it, but it is arguably the best. It uses JS for the type of thing that JS is especially good for, interacting with the web page. Get it working and debugged in JS, then it is a relatively simple matter to call that function from the applet.
How can I insert some text into a textbox of another program using java. for example, yahoo messenger chatbox.
I'm not trying to make a yahoo bot, It's just an example of what I'm looking for.
Thank you!
As Jonathon noted in the comment, you can try using java.awt.Robot. But you'd need to know the exact location of target text field, and have it visible on the screen.
You can have something like:
Robot robot = new Robot();
robot.mouseMove(xCoord, yCoord);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.keyPress(50);
robot.keyPress(51);
Apart from that, you'd need the application to provide some native API to interact with its form, and use it via JNI.
You should use JNI (or better, JNA) and send Windows Messages to the other programs textbox. I assume the other program is not a Swing App (in which case only AWT Robot works), and by sending native windows messages you can reliable find the other programs textbox even if it doesn't has the focus or is hidden in the background.
Hoping someone can point me in the right direction.
I'm quite new to Java and wanting to build a small app to practice etc.
Anyway I want to fill out a form on a site and grab the data. I have had a look at HtmlUnit and HtmlComponents and think I have most of the design covered.
Something I can't figure out is the site has a single captcha and I want my desktop app to popup a window where I would enter the captcha (manually, I'm not creating a bot).
Is this possible in Java?
It's possible and in fact JDownloader is doing it. It's open source, so you can take a look to its code.
As mentioned before JDownloader does this technique quite well. You mentioned the source is rather difficult to understand, so I'll explain the basics of what one would do.
First you would want to create your code that will fill in the form, once the form hits the captcha have it open up a frame that has a spot for an image (which will be the captcha image), a textfield, and a submit button. The submit button should have an action that will send the text from the textfield to the captcha text field in the form.
Summary:
1: Create you class that will fill in the form
2: Once it gets to the capthca make it open your 'captcha solving frame'
3: Fill in the text field and create an actionPerformed on the button that will send your string to the textfield in the form
4: Throw in some sort of catch in case you improperly fill in the captcha
On a side note, this would be easier and considerably less verbose if done with Groovy (or a scripting language) rather than Java.