Controlling a browser from java

hello experts,
i want to open an web dynpro URL in a browser and navigate through the URL , like putting values in the input box and click the buttons from java code .
Actually it is exactly like an automated test tool in java to navigate and render the given web dynpro URL with the test data given.
its very please help.
Regards,
Karthik

Hello Karthik,
I'm using Selenium to do something similar. You can find more information at http://seleniumhq.org/
The documentation can be found at http://seleniumhq.org/documentation/ and you can find a tutorial implementation for Java at http://seleniumhq.org/documentation/tutorials/
You can use a new Java Project to start using Selenium, just in case you feel confused.
I've been using Selenium for some time now, you will learn some tricks during the way. And you'd probably take a look on waitForCondition function, since you'd need some calls in order to wait for webdynpro ajax requests to populate tables (before doing your assertions).
Hope it helps.
Regards,
Daniel

Similar Messages

  • Close parent window of Mozilla browser from Java

    Hi All,
    I want to open a URL in a controlled browser from java stand alone application. I was able to do this in Netscape of UNIX OS. The method followed is given below.
    1. Launch a temporary HTML file which contains Javascript (to launch the URL in a controlled window). This is done using --- Runtime.getRuntime().exec() method.
    2. Close the parent HTML file on 'onLoad' using Javascript. (self.close).
    [ I tried window.close() & top.close() also.]
    Now I need to support the same for "Mozilla" also. But mozilla just ignores the close() command of Javascript.
    1. Is there any alternative way to close the parent window in Mozilla browser ?
    2. Is there any way to close the parent window from java by using 'Process' class/ threads/ ??
    3. Any other way???
    Note : I am using the intermediate window for using Javascript. (controlling the browser properties). Since Java cannot communicate to Javascript directly, I am forced to have such an intermediate HTML file.
    Thanks in advance.
    surekha_Venugopal.

    Some more details :
    Mozilla browser will close a window using window.close() command, but only if the window is opened by the script. If not it will not close it.
    Here, I am opening the window from Java application. That is why closure of the window is failing.
    Trying to find a solution.
    Regards,
    Surekha_Venogopal

  • Launching Browser from Java when Browser URL is very  long

    Hi,
    I am trying to launch a browser from Java.
    I am doing the following.
    String command = "cmd" + "/c" + "start" + " browserURL";
    Process p = Runtime.getRuntime()exec(command);
    Note: My browserURL is very long.
    Now the browser is invoked. But the URL shown is incomplete and hence
    browser is unable to open the required application.
    Can someone help me in this.
    One way is to increase the buffer size on the command prompt?
    Is there any java command for this?
    Is there any other way to solve this issue.
    Thanks,
    AR

    this is my second time posting this, take note of it. I can't remember where i got it from, but credits go to the person that wrote it. It has helped me out thousands of times!!!
    to use, compile, then call from your program:
    org.newio.utils.BrowserLauncher.openURL("your url here")dfwtc
    package org.newio.utils;
    import java.io.File;
    import java.io.IOException;
    import java.lang.reflect.*;
    public class BrowserLauncher
        private static int jvm;
        private static Object browser;
        private static boolean loadedWithoutErrors;
        private static Class mrjFileUtilsClass;
        private static Class mrjOSTypeClass;
        private static Class macOSErrorClass;
        private static Class aeDescClass;
        private static Constructor aeTargetConstructor;
        private static Constructor appleEventConstructor;
        private static Constructor aeDescConstructor;
        private static Method findFolder;
        private static Method getFileType;
        private static Method makeOSType;
        private static Method putParameter;
        private static Method sendNoReply;
        private static Object kSystemFolderType;
        private static Integer keyDirectObject;
        private static Integer kAutoGenerateReturnID;
        private static Integer kAnyTransactionID;
        private static final int MRJ_2_0 = 0;
        private static final int MRJ_2_1 = 1;
        private static final int WINDOWS_NT = 2;
        private static final int WINDOWS_9x = 3;
        private static final int OTHER = -1;
        private static final String FINDER_TYPE = "FNDR";
        private static final String FINDER_CREATOR = "MACS";
        private static final String GURL_EVENT = "GURL";
        private static final String FIRST_WINDOWS_PARAMETER = "/c";
        private static final String SECOND_WINDOWS_PARAMETER = "start";
        private static final String NETSCAPE_OPEN_PARAMETER_START = " -remote 'openURL(";
        private static final String NETSCAPE_OPEN_PARAMETER_END = ")'";
        private static String errorMessage;
        private BrowserLauncher()
        private static boolean loadClasses()
            switch(jvm)
            default:
                break;
            case 0: // '\0'
                try
                    Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget");
                    macOSErrorClass = Class.forName("com.apple.MacOS.MacOSError");
                    Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils");
                    Class appleEventClass = Class.forName("com.apple.MacOS.AppleEvent");
                    Class aeClass = Class.forName("com.apple.MacOS.ae");
                    aeDescClass = Class.forName("com.apple.MacOS.AEDesc");
                    aeTargetConstructor = aeTargetClass.getDeclaredConstructor(new Class[] {
                        Integer.TYPE
                    appleEventConstructor = appleEventClass.getDeclaredConstructor(new Class[] {
                        Integer.TYPE, Integer.TYPE, aeTargetClass, Integer.TYPE, Integer.TYPE
                    aeDescConstructor = aeDescClass.getDeclaredConstructor(new Class[] {
                        java.lang.String.class
                    makeOSType = osUtilsClass.getDeclaredMethod("makeOSType", new Class[] {
                        java.lang.String.class
                    putParameter = appleEventClass.getDeclaredMethod("putParameter", new Class[] {
                        Integer.TYPE, aeDescClass
                    sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply", new Class[0]);
                    Field keyDirectObjectField = aeClass.getDeclaredField("keyDirectObject");
                    keyDirectObject = (Integer)keyDirectObjectField.get(null);
                    Field autoGenerateReturnIDField = appleEventClass.getDeclaredField("kAutoGenerateReturnID");
                    kAutoGenerateReturnID = (Integer)autoGenerateReturnIDField.get(null);
                    Field anyTransactionIDField = appleEventClass.getDeclaredField("kAnyTransactionID");
                    kAnyTransactionID = (Integer)anyTransactionIDField.get(null);
                    break;
                catch(ClassNotFoundException cnfe)
                    errorMessage = cnfe.getMessage();
                    return false;
                catch(NoSuchMethodException nsme)
                    errorMessage = nsme.getMessage();
                    return false;
                catch(NoSuchFieldException nsfe)
                    errorMessage = nsfe.getMessage();
                    return false;
                catch(IllegalAccessException iae)
                    errorMessage = iae.getMessage();
                return false;
            case 1: // '\001'
                try
                    mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");
                    mrjOSTypeClass = Class.forName("com.apple.mrj.MRJOSType");
                    Field systemFolderField = mrjFileUtilsClass.getDeclaredField("kSystemFolderType");
                    kSystemFolderType = systemFolderField.get(null);
                    findFolder = mrjFileUtilsClass.getDeclaredMethod("findFolder", new Class[] {
                        mrjOSTypeClass
                    getFileType = mrjFileUtilsClass.getDeclaredMethod("getFileType", new Class[] {
                        java.io.File.class
                    break;
                catch(ClassNotFoundException cnfe)
                    errorMessage = cnfe.getMessage();
                    return false;
                catch(NoSuchFieldException nsfe)
                    errorMessage = nsfe.getMessage();
                    return false;
                catch(NoSuchMethodException nsme)
                    errorMessage = nsme.getMessage();
                    return false;
                catch(SecurityException se)
                    errorMessage = se.getMessage();
                    return false;
                catch(IllegalAccessException iae)
                    errorMessage = iae.getMessage();
                return false;
            return true;
        private static Object locateBrowser()
            if(browser != null)
                return browser;
            switch(jvm)
            case 0: // '\0'
                try
                    Integer finderCreatorCode = (Integer)makeOSType.invoke(null, new Object[] {
                        "MACS"
                    Object aeTarget = aeTargetConstructor.newInstance(new Object[] {
                        finderCreatorCode
                    Integer gurlType = (Integer)makeOSType.invoke(null, new Object[] {
                        "GURL"
                    Object appleEvent = appleEventConstructor.newInstance(new Object[] {
                        gurlType, gurlType, aeTarget, kAutoGenerateReturnID, kAnyTransactionID
                    return appleEvent;
                catch(IllegalAccessException iae)
                    browser = null;
                    errorMessage = iae.getMessage();
                    return browser;
                catch(InstantiationException ie)
                    browser = null;
                    errorMessage = ie.getMessage();
                    return browser;
                catch(InvocationTargetException ite)
                    browser = null;
                    errorMessage = ite.getMessage();
                    return browser;
            case 1: // '\001'
                File systemFolder;
                try
                    systemFolder = (File)findFolder.invoke(null, new Object[] {
                        kSystemFolderType
                catch(IllegalArgumentException iare)
                    browser = null;
                    errorMessage = iare.getMessage();
                    return browser;
                catch(IllegalAccessException iae)
                    browser = null;
                    errorMessage = iae.getMessage();
                    return browser;
                catch(InvocationTargetException ite)
                    browser = null;
                    errorMessage = ite.getTargetException().getClass() + ": " + ite.getTargetException().getMessage();
                    return browser;
                String systemFolderFiles[] = systemFolder.list();
                for(int i = 0; i < systemFolderFiles.length; i++)
                    try
                        File file = new File(systemFolder, systemFolderFiles);
    if(file.isFile())
    Object fileType = getFileType.invoke(null, new Object[] {
    file
    if("FNDR".equals(fileType.toString()))
    browser = file.toString();
    return browser;
    catch(IllegalArgumentException iare)
    browser = browser;
    errorMessage = iare.getMessage();
    return null;
    catch(IllegalAccessException iae)
    browser = null;
    errorMessage = iae.getMessage();
    return browser;
    catch(InvocationTargetException ite)
    browser = null;
    errorMessage = ite.getTargetException().getClass() + ": " + ite.getTargetException().getMessage();
    return browser;
    browser = null;
    break;
    case 2: // '\002'
    browser = "cmd.exe";
    break;
    case 3: // '\003'
    browser = "command.com";
    break;
    case -1:
    default:
    browser = "netscape";
    break;
    return browser;
    public static void openURL(String url)
    throws IOException
    if(!loadedWithoutErrors)
    throw new IOException("Exception in finding browser: " + errorMessage);
    Object browser = locateBrowser();
    if(browser == null)
    throw new IOException("Unable to locate browser: " + errorMessage);
    switch(jvm)
    case 0: // '\0'
    Object aeDesc = null;
    try
    try
    aeDesc = aeDescConstructor.newInstance(new Object[] {
    url
    putParameter.invoke(browser, new Object[] {
    keyDirectObject, aeDesc
    sendNoReply.invoke(browser, new Object[0]);
    catch(InvocationTargetException ite)
    throw new IOException("InvocationTargetException while creating AEDesc: " + ite.getMessage());
    catch(IllegalAccessException iae)
    throw new IOException("IllegalAccessException while building AppleEvent: " + iae.getMessage());
    catch(InstantiationException ie)
    throw new IOException("InstantiationException while creating AEDesc: " + ie.getMessage());
    break;
    finally
    aeDesc = null;
    browser = null;
    case 1: // '\001'
    Runtime.getRuntime().exec(new String[] {
    (String)browser, url
    break;
    case 2: // '\002'
    case 3: // '\003'
    Runtime.getRuntime().exec(new String[] {
    (String)browser, "/c", "start", url
    break;
    case -1:
    Process process = Runtime.getRuntime().exec((String)browser + " -remote 'openURL(" + url + ")'");
    try
    int exitCode = process.waitFor();
    if(exitCode != 0)
    Runtime.getRuntime().exec(new String[] {
    (String)browser, url
    catch(InterruptedException ie)
    throw new IOException("InterruptedException while launching browser: " + ie.getMessage());
    break;
    default:
    Runtime.getRuntime().exec(new String[] {
    (String)browser, url
    break;
    static
    loadedWithoutErrors = true;
    String osName = System.getProperty("os.name");
    if("Mac OS".equals(osName))
    String mrjVersion = System.getProperty("mrj.version");
    String majorMRJVersion = mrjVersion.substring(0, 3);
    try
    double version = Double.valueOf(majorMRJVersion).doubleValue();
    if(version == 2D)
    jvm = 0;
    } else
    if(version >= 2.1000000000000001D)
    jvm = 1;
    } else
    loadedWithoutErrors = false;
    errorMessage = "Unsupported MRJ version: " + version;
    catch(NumberFormatException numberformatexception)
    loadedWithoutErrors = false;
    errorMessage = "Invalid MRJ version: " + mrjVersion;
    } else
    if(osName.startsWith("Windows"))
    if(osName.indexOf("9") != -1)
    jvm = 3;
    } else
    jvm = 2;
    } else
    jvm = -1;
    if(loadedWithoutErrors)
    loadedWithoutErrors = loadClasses();
    suck my balls

  • Easiest way to launch a link to the default browser from java?

    Is there an easy way to launch a link in the default browser from java? Ideally I would have a graphic in a cell that when clicked on would open a new window/tab in the default browser. This would be done in SWT, but it might be similar to swing, awt, etc. Any ideas?

    If you are using Java 1.5 or earlier, I found the browser launch code found here to work fairly well: http://www.centerkey.com/java/browser

  • Controling windows volume from java

    Hi! Firstable, sorry for my English.
    My question is very simple
    How can I control windows' volume from java?
    I've searched everywhere, but I found nothing.
    JMF did not help me, I just could control a line, but I want to control the master volume of my pc.
    Thanks in advance...

    If you can identify a Windows command that does what you want, then you can execute it using Java's ProcessBuilder class nethods. If not, you can use Java Native Interface (JNI) or one of its variations to create an interface from Java to C/C++ code in Windows.

  • How to control browser from java program?

    I want to retrieve the url currently loaded in my default browser. How to achieve this task using java program? I dont know how to access browser using java.

    Peter__Lawrey wrote:
    Actually Desktop.open only works for downloaded pages.
    Instead you can use this to get the browser to download the page and display it.
    Desktop.getDesktop().browse(URI.create("http://www.google.co.uk"));
    First of all thanks for your reply Mr Peter__Lawrey.
    I want to just retrieve the urls loaded in the default webbrowser, not the content of the url or the task of opening the default browser with the specific url.

  • How to open a web browser from java

    Hi
    Would anybody please help me with this. I need to open a web browser from my java app but I don't know. What method I can use?
    Thanks.
    Hung.

    You can use the Runtime class for this. It can run any command. So, you can run the .exe file of your Web browser.
    The following code will run Internet Explorer (assuming iexplorer.exe is in C:\Program Files\Internet Explorer):
    import java.lang.Runtime;
    public class Explore{
    public static void main(String[] args) {
    try{
    Process p = Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\iexplore");
    }catch (Exception e) {
    System.out.println("Exception: " + e);

  • How to invoke browser from java program in Solaris ?

    Hi all,
    Is there any way by which a browser can be opened with specific URL, from a java program in solaris OS ?
    In windows I am able to do so by using "rundll32 url.dll,FileProtocolHandler".
    Thanks,
    ngs

    Well, how is a browser normally invoked on Solaris? And have a look at JDIC, maybe it helps you.

  • Launhing browser from java

    Hi
    I'm Launching jsp from my java code with the help of Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + strUrl); when this jsp is Launched it passes the parameters to another jsp with action property of form.and the new browser is Launched what i want to do is when this browser is launched i want to customize the browser visibility.Like hiding toollbar.setting scrollability false etc. can someone guide me how to perform this

    You need to use javaScript for this, not java, have a google, theres loads of javaScript stuff on the web.

  • Problem with opening browser from Java app.

    Hi guys, I'm not sure if this is the right place to post this, so please excuse me if I'm wrong. I'm trying to open an html page (it's a help file) from a Java application. I'm currently using java.awt.Desktop.     browse(URI uri); which gets the job done, as long as I don't pass any parameters to the page. (e.g. http://www.site.com/site.html?param1=1). Doing that gives me an IOException. Is there a way to do this without using the JNLP API?

    This is the file path copied directly from the browser's address bar:
    file:///home/riaan/EMCHelp/Help.html?page=WorkFlowActivityCategory.html"{code}
    Which causes the app to throw an exception, but when I change it to:
    {code}file:///home/riaan/EMCHelp/Help.html{code}
    it opens Help.html in the browser.  That's why I thought that it might be the query that's a problem.  Perhaps it's a simple issue of not escaping a character or something that I failed to see.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Lauch IE browser from Java Application

    Hi, I am interested in launching an IE window from a Java application. Is there a way
    to accomplish this? Thanks.

    Again, any other way that allows me to start a java application and IE browser on WINDOWS2000 would be helpful too.

  • Open web browser from java application to specific page

    Hi,
    I used the code from http://www.javaworld.com/javaworld/javatips/jw-javatip66.html to open a web browser to a specific URL. That worked great! However, I run into a problem if the URL targets a specific page, for example, "http://www.yahoo.com/news.html" would give me an problem with the shortcut problem. Any ideas how to get around that?
    The command rundll32 url.dll,FileProtocolHandler http://www.yahoo.com/news/ would work fine, except anything ends with .htm or .html.
    Thanks,
    David

    It looks like url.dll doesnt like .htm or .html files. For more info look here: http://www.jsiinc.com/SUBI/tip4100/rh4162.htm
    For some reason it is confused by the 'm' character in .html which is odd considering it has no problems with .com
    So if you want to keep using url.dll, do something like this:
    replace ".htm" with ".ht%6D"

  • Opening new default browser from java app

    Hi There,
    I would like to know if there is away to execute the following in a Java app that will open a new browser window.......in other words, I don't want it to take over the already opened window - just open a new window every time.
    Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler
    www.google.co.nz");Any help with this would be greatly receievd.

    There might be. However it would be done by modifying that Windows-specific command that you have in red there. As such it's nothing to do with Java. Searching in Windows-specific websites might get you somewhere.
    However Firefox gives the choice (new window, new tab, or same tab in same window) to the user as a configuration option, so I wouldn't bet on getting somewhere. I don't know if IE has a similar configuration option.

  • Controlling external programs from Java

    Hi,
    I try to invoke an external command-line program in Windows 2000 fron Java. I do this by
    Process proc = Runtime.getRuntime().exec(cmd);
    cmd is a String representing a command. For instance I try to control the gnupg program by
    "cmd /c C:\\gnupg\\gpg --list-keys"
    This works fine. But when I want to make a more advanced control, when gnupg waits for more than one input, and that input can't be put on the same line I get problems.
    When running gpg --edit-key SomeKey on the command line I have to enter
    trust - return - 5 - return - yes - return - quit
    How do I do this?

    this is how to do it! gotta listen to the output to prevent deadlock. you can pass in parameters o the initial call as well (a string array, where string[0] = command, string[...] = input argument) or write it to the output stream of the process.
    hope this helps
    public void run_command(String starting_command, String[] further_commands)
    Process proc = Runtime.getRuntime().exec(starting_command);
    Listener.make(proc.getInputStream());//these listen to the streams
    Listener.make(proc.getErrorStream());//which prevents deadlock
    PrintWriter writer = new PrintWriter(new OutputStreamWriter(proc.getOutputStream()));
    for(int i = 0;i < further_commands.length;i++)
    writer.println(further_commands);//you could put the extra stuff as the first string in this array
    import java.io.*;
    public class Listener extends Runnable
    BufferedReader reader;
    public static void make(InputStream in)
    Listener l = new Listener(in);
    Thread thread = new Thread(l);
    thread.start();
    public Listener(InputStream in)
    reader = new BufferedReader(new InputStreamReader(in));
    public void run()
    String string;
    while(true)
    string = reader.readLine();
    try
    Thread.sleep(1000);
    catch(Exception e)

  • Open Browser with No Address Bar from Java

    How to open a IE Browser from Java with no address bar, tool bar etc ?
    I am able to open browser like the listed code, but the requirement for me is it has to open with no "Address Bar", buttons.
    I know we can do that in "Javascript" but how to or is there a way to do that in java/swing.
    Any help is greatly appreciated.
    String WIN_FLAG = "url.dll,FileProtocolHandler";
    String WIN_PATH = "rundll32";
    String url = "www.google.com"
    String cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
    Runtime.getRuntime().exec( cmd );

    Use javascript for this. I would do it this way....
    You can decide with JS if you want tot hide so elements from your browser. Should not be very difficult to implement

Maybe you are looking for