Switch browser : it works, but not visible at screen

Hi all,
I’m a new user of Robot Framework, i m doing simples actions on browsers.
When i use Switch Browser, it works : actions are made on my differents sessions but not at screen. there isnt visual switch. I need to demonstrate the RF work and at the switch browser moment it’s not really clear.
It is a normal thing ?
It is possible to show at screen the switch browser to be able to continue to see the currents actions ?

Thanks

Fabrice

Hi Fabrice,

At first It wasn’t clear what you were asking so I adapted the example from the documentation Switch Browser and created the example below that demonstrates what I think you are asking.

When I run this example, it opens a firefox window to google.com, it then opens a chrome window to yahoo.com which now sits in front of the firefox window, because I didn’t full screen the chrome window you can see some of the firefox window but it’s obscured.

when Switch Browser switches to firefox, chrome remains as the front most window, you can see some activity is happening on the firefox window but can’t see what because it’s behind the chrome window.

If I’m understanding correctly you were expecting the firefox window to come to the front when Switch Browser is called?

I’m not sure whether this is expected behaviour or not, perhaps someone who is more knowledgable than me on SeleniumLibrary can confirm? I don’t see any mention in the documentation about this.

I also don’t know if different platforms affect this behaviour, I reproduced what I believe is you issue on MacOS 11.2, it may behave differently on windows? I would expect it to be the same on Linux as MacOS.

Another option if you really need the browser window in the front for people watching the automation could be to use another library to bring the browser to the foreground SikuliLibrary or flaui might be useful to do that.

FYI - the Capture Page Screenshot call does allow me to confirm the actions I expected were performed in the browser I expected.

*** Settings ***
Library    SeleniumLibrary


*** Test Cases ***
Fabrice
	Open Browser 	http://google.com	ff
	Location Should Contain 	google.com
	Open Browser 	http://yahoo.com	gc	alias=second
	Location Should Contain 	yahoo.com
	Switch Browser 	1 	# index
	Page Should Contain 	Gmail
	Input Text 	q 	robot framework
	Press Keys 	q 	ENTER
	Capture Page Screenshot
	Switch Browser 	second 	# alias
	Page Should Contain 	Company info
	Input Text 	p 	robot framework
	Press Keys 	p 	ENTER
	Capture Page Screenshot
	Close All Browsers

I don’t know how much help this is, hopefully some,

Dave.

Hi Dave,
Thanks for your answer. It 's exactly that. When i call Switch Browser, i want my active browser on the first plan, to see the currents actions.
When i try your example, it is ok for the results but not on live : there is no visual switch of browsers.
i need to show to anothers persons and it would be better
if you have a idea, i take it…
Thanks again

I m gonna see the libraries that you told me
Thx
Fabrice

Hi Fabrice,

From my usage of SeleniumLibrary, I have noticed that sometimes the browser will jump to the foreground but i’m not sure what triggers it to happen, I thought it was the click keyword so I tried adding a step Click Element q but that didn’t work so I didn’t suggest it, but maybe it’s a click link or it might be the browser doing it when a page loads I don’t know.

SikuliLibrary is a great tool to have as an all purpose last resort, it works by clicking images so it works on every os / every application, but it’s not always the most accurate especially if things look visually similar.
flaui allows you to use xpaths to identify object in an application but it only works with windows I wish I knew of something similar for MacOS and Linux

When you switch browser are the browser sessions different browsers or the same? i.e. edge and firefox or chrome and chrome? if they are different then having SikuliLibrary click the browsers icon on the taskbar / dock / etc might be all you need to do, then return to SeleniumLibrary :crossed_fingers:t2:

It might also be worthwhile raising a feature request with SeleniumLibrary project to have an option on the Switch Browser keyword to bring the browser to the foreground, not sure if they’ll be able to do that, depends if Selenium has that capability, but no harm in asking.

Dave.

HI Dave,

Thanks again for these informations. I must to see SikuliLibrary asap. For flaui, unfortunatly i 'm under Linux.
To answer you, i use the same browser : In multi Browser sessions of firefox. If i find anything i ll write the solution here.

Fabrice

Hi Fabrice,

In that case SikuliLibrary is the only library I know will work for you, but because you are using 2 firefox sessions it might be difficult to tell them apart, which distro / window manager are you using? the reason I ask, if you are using something like mint that has a windows style look and feel with a task bar then the icon combined with text on the task bar might be unique, but if your using something like elementary os with a dock it could be difficult to tell the 2 firefox sessions apart.

If I think of anything else i’ll mention it,

Dave.

Hi dave,

Apparentlly window management is XFCE…

Fabrice

Hi Fabrice,

Not sure of your programming skills in python? but you can create python functions and use them as keywords in robot framework.

I found this example for window management in XFCE with python:

I’ve never done this myself, but hopefully you could adapt that example to create a python function that activates a window based on a window title.
Then you could use Get Title after Switch Browser to get the title then pass the title to the python function.

I did have a look at the pywinauto python library, this is something i’d been keeping an eye on as it was aiming to be a cross platform test automation library but it’s activate window is windows only still.

Dave.

Dave,

I m not a devloper, just an “evolued” user, but i m going to look at this way

thx again

Fabrice

Hi Dave,

It’s all right, i found a solution. With your link, i made searches and i done that :

On the Keyword “Switch Browser” of SeleniumLibrary/Keywords on the “try”, i ve added

handle_of_the_window = self.driver.current_window_handle
self.driver.switch_to.window(handle_of_the_window)
self.driver.minimize_window()
self.driver.set_window_rect(0, 0)
self.driver.maximize_window()

At each switch browser : it force current handle+minimize+maximize

It works fine

Thanks again for your time and your help

Fabrice

1 Like

Hello Everyone, Hello Fabrice
I am new here, I am not a developer and I am having the same problem as Fabrice.
How to modify the Keyword Switch Browser in the SeleniumLibrary in order to add your code?
I am having the exact same problem.
Sorry for my broken English, I am French.
Josue

Salut Josue,

Je suis francais aussi alors on va le faire en francais…:slight_smile:
D’abord, bonne annee !!

Ensuite, pour effectuer la modif j’ai en effet oublié de dire le fichier a editer, donc :

Tu dois editer le fichier [TonInstall]/SeleniumLibrary/Keywords/browsermanagement.py

Dans le fichier tu recherches “def switch_browser” (c’est la fonction appellée)

Dans le “try:” en dessous de la partie doc, tu colles le code donné en dessous de la ligne “self.drivers.switch…” en respectant l’indentation

Tu sauves, tu relances

Voila, bon courage

Fabrice