I have created Test.py file which has some function in it and using those function names as Keywords in sample.robot file.
Ex: - Test.py
def Launch_URL(url):driver.get(url)def article(publication): do something here
Sample.robot
Library Selenium2Library
Library Test.py*** Test Cases ****Open app Launch URL "https://stackoverflow.com"article somethingClick Element xpath=/html/body/div[1]/div/div/button/i
Apart from the derived keywords in .py I also want to use built in Keyword Click Element
in robot file. When the I run the above script it is throwing me No Browser Open
error for Click Element
keyword.
The click element keyword (and all of the other keywords) relies on a browser opened by Selenium2Library. Since you are opening it with the python selenium module rather than the robot library, the Selenium2Library keywords do not know about the browser.
If you need to use the same browser both for Selenium2Library and through python code, The best way is to open the browser with Selenium2Library, and then get the driver reference from it to use it in python.
Assuming that you've opened the browser using the open browser or create webdriver keyword, you can use the driver for that browser in python like this:
from robot.libraries.BuiltIn import BuiltIn
def Launch_URL(url):se2lib = BuiltIn().get_library_instance('Selenium2Library')driver = se2lib._current_browser()driver.get(url)
If you do not want to use open browser
in your test, and expect Launch URL
to be the first keyword you use, you can call open_browser
from your keyword:
def Launch_URL(url):se2lib = BuiltIn().get_library_instance('Selenium2Library')se2lib.open_browser(url, "chrome")
Here's another similar question: Pass existing Webdriver object to custom Python library for Robot Framework
If you are wanting to write keywords in python that use both the built-in keywords and also have directly access to the selenium module, you might want to consider using this page object library, which handles all of the details for you.
Note: the use of the private method _current_browser
is unavoidable in version 2 of Selenium2Library. A public interface is being made available in version 3 of SeleniumLibrary. See github issue #882