# Using SeleniumLibrary and Python/Java keywords with same browser instance

**URL:** <https://forum.robotframework.org/t/using-seleniumlibrary-and-python-java-keywords-with-same-browser-instance/675>\
**Category:** Robot Framework\
**Created:** [3 September 2020 09:48 UTC](https://forum.robotframework.org/t/using-seleniumlibrary-and-python-java-keywords-with-same-browser-instance/675 "2020-09-03T09:48:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Apoorva1](https://avatars.discourse-cdn.com/v4/letter/a/2acd7d/32.png) [@Apoorva1](https://forum.robotframework.org/u/Apoorva1)\
**Post date:** [3 September 2020 09:48 UTC](https://forum.robotframework.org/t/using-seleniumlibrary-and-python-java-keywords-with-same-browser-instance/675/1 "2020-09-03T09:48:47Z")

</div>

Hi All,

I am trying to use Robot Framework’s -SeleniumLibrary, Custom Library in Python and Custom keyword in Java in the same test case.  
I wanted to use the Robot Framework - SeleniumLibrary’s Open Browser keyword to open a browser instance and use the same browser which was opened from Robot Framework to be used by a Python / Java’s custom keyword. But a new browser is getting opened when I try to use these custom keywords.

Sample code of the Python’s Custom Keyword:

```
def login_using_selenium(self):  
        driver = webdriver.Chrome()
        driver.get("https://abc.com")
        element = driver.find_element_by_id("userId")
        element.send_keys("33")
        element = driver.find_element_by_id("password")
        element.send_keys("128")
        element.click()

```

Can anyone help me out in using the same browser in the Robot Framework test case along with RF-SeleniumLIbrary and other Custom Keywords?

Thanks!

---

<div class="post-metadata">

**Author:** ![René](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ren%C3%A9/32/7_2.png) [@René](https://forum.robotframework.org/u/Ren%C3%A9)\
**Post date:** [4 September 2020 15:19 UTC](https://forum.robotframework.org/t/using-seleniumlibrary-and-python-java-keywords-with-same-browser-instance/675/2 "2020-09-04T15:19:17Z")

</div>

Hi @Apoorva1 ,

i wouldn’t recommend to use it like this!  
In your example you just use Selenium itself, without using the capabilities of SeleniumLibrary. Like automatic locator strategy etc.

What you should do:  
Import the SeleniumLibrary FIRST in your robot tests and then import your library:

```
Library SeleniumLibrary
Library YourCustomLib

```

When you have done this, you have the possibility to get the SeleniumLibrary instance (the object of the library that also knows all open browsers etc) from RobotFramework  
To do so, you call the BuiltIn keyword `Get Library Instance` from your library in Python.

```
from robot.libraries.BuiltIn import BuiltIn

SL = BuiltIn().get_library_instance("SeleniumLibrary")

class YourCustomLib:

    def login_user(self):
        SL.press_keys("userId", "33")
        SL.press_keys("password", "128")
        SL.click_element("login_btn")

```

Your Robot Test would look like

```
***Settings***
Library SeleniumLibrary
Library YourCustomLib

***Test Cases***
Test
     Open Browser https://abc.com browser=chrome
     Login User

```

You will not have code completion in Python while calling the keywords from SeleniumLibrary with the SL object. This could be fixed with a generated ` __init__.pyi` file.  
But this is another topic.

An alternative to SeleniumLibrary would be the new [Browser](https://github.com/MarketSquare/robotframework-browser) library.

---

<div class="post-metadata">

**Author:** ![Apoorva1](https://avatars.discourse-cdn.com/v4/letter/a/2acd7d/32.png) [@Apoorva1](https://forum.robotframework.org/u/Apoorva1)\
**Post date:** [5 October 2020 14:41 UTC](https://forum.robotframework.org/t/using-seleniumlibrary-and-python-java-keywords-with-same-browser-instance/675/3 "2020-10-05T14:41:58Z")

</div>

Hi @René

Thank you for your reply! I really appreciate it. Will try out the Browser library as well. But before that, I would like to know if there are any ways of using the browser instance vice versa.

I already have the Python/ Java code in place, which has it’s browser instance open. And then I would like to perform operations in the Robot Test Suite with the same browser instance.

\*\*\* Settings \*\*\*  
Library SeleniumLibrary  
Library MyCustomLib

\*\*\* Test Cases \*\*\*  
Test  
Login User  
Input Text id:HomePageInput\_email [xyz@gmail.com](mailto:xyz@gmail.com)

It’ll be really helpful if you could help us out on the same.

Thanks!  
Apoorva A

---

<div class="post-metadata">

**Author:** ![René](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ren%C3%A9/32/7_2.png) [@René](https://forum.robotframework.org/u/Ren%C3%A9)\
**Post date:** [7 October 2020 21:29 UTC](https://forum.robotframework.org/t/using-seleniumlibrary-and-python-java-keywords-with-same-browser-instance/675/4 "2020-10-07T21:29:20Z")

</div>

Ifaik if you create a driver like in your example, it will be hard to habd over that driver to SeleniumLibrary. Maybe not impossible.

But i would check out public api of SeleniumLibrary.  
Amd SeleniumLibrary 5.0 will also have code completion in python…
