Passing a robotframework instance to selenium2Library

241 views
Skip to first unread message

SeanRF

unread,
Jul 18, 2012, 8:46:12 AM7/18/12
to robotframe...@googlegroups.com
Using python you can get the active selenium instance by

sel = BuiltIn().get_library_instance('SeleniumLibrary').selenium

But how is this done with the Selenium2Library?


Kevin O.

unread,
Jul 18, 2012, 10:41:29 AM7/18/12
to robotframe...@googlegroups.com
Keep in mind there can be several browsers/webdrivers open, but you can access the active one like this:

BuiltIn().get_library_instance('Selenium2Library')._current_browser() # returns a WebDriver object

below is some working code to workaround the iframe issue without patching until the next release:

from Selenium2Library import Selenium2Library
from robot.libraries.BuiltIn import BuiltIn


def select_iframe(locator):
    """Sets iframe identified by `locator` as current frame.
    
    This is a temporary workaround until Selenium2Library is
    patched. Key attributes for frames are `id` and `name.`
     See `introduction` for details about locating elements.
    """
    seleniumlib = _get_instance()
    seleniumlib._info("Selecting iframe '%s'." % locator)
    element = seleniumlib._element_find(locator, True, True, tag='iframe')
    seleniumlib._current_browser().switch_to_frame(element)
    
def _get_instance():
    return BuiltIn().get_library_instance('Selenium2Library')
Reply all
Reply to author
Forward
0 new messages