Friday, 15 February 2013

Uses of browserbot in selenium

Some time we need to access application dom in selenium . Dom can be accessed in selenium  by using browserbot object.



To understand browserbot uses . Please go through following code :
Ex.
        <html>
        <head>
        <script>
        var i=10;
        function fun()
        {
           ------
           ------
        }
        </script>
        </head>
        <body>
        <input id="id1" name="id1" value="Input"/>
        </body>
        </html>

Suppose you want to access variable i in your code . This can be done by following line :

      String value=selenium.getEval("this.browserbot.getUserWindow().i");

Suppose you want to call fun() method from selenium code . This can be done by

       String value=selenium.getEval("this.browserbot.getUserWindow().fun()");

 Suppose you want to access input box having "id1". Then code is below

   String value=selenium.getEval("this.browserbot.getUserWindow().document.getElementById('id1').value");

No comments:

Post a Comment