SWT Browser -- get selected text - java

I am using a Browser view in my application and i need to get the text selected by user. I tried creating mouse event but nothing is working. I am using following link to create the browser:
http://180.179.103.253/q3/twapp/process.php?mdl=onetimeurl&id=1061&deviceid=9d2aefc2-a386-4afc-b307-44f41ec8311d&test=1
I also checked in documentation, there is no method like getSelectionText() in SWT browser.

you could achieve this by executing java script function in the browser from your View.Write a java script to get the selection the text and execute it in the browser.
Look at the Browser API:
browser.execute(script);
browser.evaluate(script);
Look at BrowserFunction interface for java-javascript call back mechanism

Related

A program that ask you which web browser you want to use

I want to make a simple program that ask you which browser you want to use.
When you'll click on a link (email or pdf for example), a program will appear instead of the browser and will ask you which browser you want to use.
First : in which code it's the best to write this?
Secondly : How to open the program and not the browser?
I need a bit of help to write this, because i don't know how begin
This is tricky. There is no uniform event for "User clicks on url" that spans all applications.
The most straightforward solution would be to create your application and register it as the default browser.
Personally I would be annoyed by having to select a browser each time I click a link so I would probably make a helper application that when it starts remembers the current default browser and then registers the browser selector as the default. And when the helper closes it would restore the default browser.
My Java is quite rusty but I think this should be possible in either language. Maybe a little trickier in Java due to the lack of a dedicated executable for your application.
For C#:
This will open the url in the default browser:
string url = "http://google.com/";
System.Diagnostics.Process.Start(url);
This will open the url in the specified browser:
System.Diagnostics.Process.Start(#"C:\Program Files\Mozilla Firefox\firefox.exe", url);
There will be an error if the browser does not exist.

set focus to java-inputdialog inside webbrowser over vb.net

I have a small application with a webbrowser in it. in this webbrowser a webpage is loaded with a JAVA applet. this java applet has input prompts like the one shown in the image
i would need to be able to type a text inside this input dialog over a vb.net button. but i am unable to set the focus onto this input programmatically.
any help appreciated!
There a few way to do that by using hooks. First one is to create local hook with SetWindowsHookEx
SetWindowsHookEx(WH_CALLWNDPROCRET, NativeMethods.HookProc,
IntPtr.Zero, (uint)AppDomain.GetCurrentThreadId());
and listen to WM_INITDIALOG windows messages, then find input textbox and insert required text.
Sample code in Suppressing Hosted WebBrowser Control Dialogs
Second way is to use SetWinEventHook function and hook EVENT_SYSTEM_DIALOGSTART events and rest of processing is the same. You can find sample code in https://github.com/jsulak/Switcheroo/blob/master/ManagedWinapi/AccessibleObjectListener.cs

Accessing a pdf opened in a new browser window with Selenium and JAVA

Language - JAVA
IDE - Eclipse
Tool - Selenium Web Driver
I have a test scenario where clicking on a link opens a new window with a pdf content being shown. The PDF shows up a form with Save and Cancel button. We don't get any element identifier using firebug for elements shown on the new window. How can I write a script to tell the driver to identify fields in the pdf and input something there followed by clicking on Save button.
Not sure if you can identify fields in a pdf using webdriver, since, in most cases, the pdf would be embedded in the browser and the fields in the pdf are not Html components.
One thing you might want to check out is using AutoIt scripting and calling this script from your host program, in your case, java program. I have not tried using AutoIt for pdf but used it for other purposes and found that it is not difficult to learn and use.
You can call AutoIt executable from java program as follows:
Runtime.getRuntime().exec("checkPDF.exe");
Since it is an executable, you might have portability issues if you plan on running your webdriver script on other platforms.
Not going to work with Selenium. PDFs are usually displayed using native desktop applications/browser plugins and that is nothing Selenium can handle in general. BTW: what do you intend to test in a PDF formular? Seems pointless to me (at first sight).
What you CAN do is: take a desktop screenshot using AWT. And you should be able to use native desktop methods to simulate mouse clicks and key presses. But that is, well, not so nice [tm] because you may need to record the click coordinates and re-record them every time the PDF changes.
Maybe related: Interacting with a PDF popup in Selenium

Export a jQuery div as a picture

I found a very nice jQuery polaroid running in a div.
Is it possible to save the result in a single image? What library should I use? I am using Java, JavaScript and Python. Is there a library for those languages?
It's not quite clear how you want to use this. A couple of use cases come to mind:
Occasionally, in your own browser. Use Windows screen capture (Alt-printscreen), paste into a graphics editor (Paint.NET), and crop.
Often, in your own browser. Install a browser plugin like IECapt http://iecapt.sourceforge.net/ or FireShot https://addons.mozilla.org/en-US/firefox/addon/5648/
Programmatically, in your own browser. Use win32 api calls to get a screenshot, crop and save. ?Linux equivalent?
For a developer, to get testing screenshots on their own machine or a test machine. Selenium RC http://saucelabs.com/blog/index.php/2009/10/selenium-tip-of-the-week-screenshot/
For a user, in their own browser:
Instrument the javascript to report thumbnail positions back to the server; write server-side code to recreate the image, give the user a 'save image as' button to download it.
use an ActiveX control (Snapsie https://github.com/nirvdrum/SnapsIE ) (WebThumb http://www.acasystems.com/en/web-thumb-activex/ ) - need permission to run, IE only
use a Java applet (SnapABug http://www.barklund.org/blog/2009/10/14/how-snapabug-works/ ) - need permission to run
use nonstandard, unsecure javascript extensions? https://developer.mozilla.org/en/Drawing_Graphics_with_Canvas#section_9 - looks like maybe you can grab part of the webpage and roll it over to a canvas? Then http://www.nihilogic.dk/labs/canvas2image/ to save it as a file.
Some related questions:
Take a screenshot of a webpage with JavaScript?
save an image with selenium & firefox
Programmatically get a screenshot of a page
JavaScript code to take a screenshot of a website without using ActiveX

How to programatically send input to a java app running in a browser window?

Consider the most excellent wordle tag cloud generator:
http://www.wordle.net/create
Entering text into the "textform" textarea and clicking the go button starts up the wordle java applet on that page. No traffic goes back to the server.
How can I cause this to happen programmatically? No hack too cheap!!
background for this question:
"tag cloud" generators?
If you mean starting it programmatically from a browser page, you can use the same type of JavaScript that that page uses, which calls the function Wordle.t() to start the applet.
If you want to call it from a Java program, you can download the Wordle.class or jar file yourself, and call the functions directly.
I'm the creator of Wordle.
In case anyone finds this page in the future, I thought it would be useful to explain that Wordle invokes its applet by constructing an applet tag with a huge <param> containing a sanitized version of whatever text you pasted in. It is the cheapest hack imaginable.

Categories