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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…