Get browser handle

42 views
Skip to first unread message

Tomas Pekarovic

unread,
Jun 5, 2014, 3:00:47 AM6/5/14
to seleniu...@googlegroups.com
Hello all.....

I'm using python for selenium and web automation.  There is one question that I'm curious.  
If I want to create remote library for selenium to use it for example with robot framework I need to prepare some keywords etc... this is not a problem...

Let's explain it on example:
I implemented commands

1. Run browser    <browser>
2. Navigate To    <url>
3. Click Button   <button id>

This communication is handled by xmlrpc... so problem is:
def run_browser(browser):
    browser
= getattr(webdriver, browser)()
   
return browser


def navigate_to(url):
    browser
= ????
   
return browser.get(url)

in step 1. you normalny starts broswer, and it will return it... 
but in step2 if you are going to  get ulr, you have problem, you don't have browser handle... 
so  to sum it up... how to get handle of started browser?  I tried to open new browser, and than get handles of opened browsers with  browser.window_handles   but it only gets handle of browser opened by selenium..

Is there any way how to get handle of browser, that is not opened by selenium? and switch to this window? Or I have to find some kind of hack to do this?


Ty



David

unread,
Jun 5, 2014, 2:08:05 PM6/5/14
to seleniu...@googlegroups.com
If you build a Robot Framework library for Selenium, you need to make the driver instance persist globally when first invoked (via keyword or at library startup) and stay persisting until torn down (via keyword or on quitting library). And all other keywords of the library simply use that persistent instance to invoke the Selenium APIs against. If you create and tear down the instance in the same session, you could create a new instance too and simply assign new instance to the same global driver variable name so that it can be reused by all keywords with no problem.

You should take a look at the Selenium2Library for Robot Framework (Python or Java version) to see how they actually implement all this stuff. Better yet, why not use/extend their library? I believe that library can be used remotely as well.

You only have more of an issue if you chose to implement Selenium remote library say in .NET, Perl, or PHP for which there is no existing Selenium2Library for RF.
Reply all
Reply to author
Forward
0 new messages