Open GoogleCodeExporter opened 9 years ago
You can save the windows' ids before switching to the 2nd window and once it's
been closed, switch back to the first one:
wins= wd.WindowHandles
wd.switchToWindow wins(1)
...
wd.switchToWindow wins(0)
Or you can switch back to the 1st window by using its name if there is one
defined:
wd.switchToWindow "2nd window name"
...
wd.switchToWindow "1st window name"
Original comment by florentbr
on 8 Apr 2014 at 5:14
Hi Florent,
Thanks for your quick response. I was not able to use the work around you have
suggested. Please find the below piece of code i am using in my project.
Request you to have a look at my code and correct me if i am doing anything
wrong.
Shouldn't it be a high priority bug? Child windows are very common in web
applications.It will be difficult to use selinium, if it doesn't have a method
to switch the focus back to parent window after closing child window.
Public Function fn_DriverScript(ByVal strurl, ByVal struid, ByVal strpaswd)
Dim selenium
Set selenium = CreateObject("SeleniumWrapper.WebDriver")
selenium.Start "firefox", strurl
selenium.setImplicitWait 5000
'Login to application
selenium.Open "/cgi/max/admin_login.w"
selenium.Type "name=h_tUserName", struid
selenium.Type "name=h_pPassword", strpaswd
selenium.clickAndWait "css=input.save"
'click on button.this will open up a child window
selenium.Click "css=img[name=""h_hButtonHV""]"
strParentWindowTitle = selenium.Title 'value is MAX: /cgi/max: Workstation
'Below line will switch the focus to child window
selenium.selectWindow "title=Mortgage Offers Search Option Screen"
selenium.clickAndWait "id=hbskip" 'Close the child window and this will load a new page in parent window
'Switch the focus back to parentwindow
selenium.selectWindow "title=" & strParentWindowTitle
strErrDescription = Err.Description
'captured error was "Window not found. The browser window may have been closed."
'Execution is stuck as selinium object instance is set to null after closing the child window
End Function
Original comment by nit.li...@gmail.com
on 9 Apr 2014 at 7:50
> I was not able to use the work around you have suggested
This is not a work around. This is how it needs to be handled with the Selenium
framework and for every binding language.
It could be a timing issue as you're saying that the parent window is reloaded
just after child window is closed.
The parent could still be loading and be without a title when the selectWindow
is called. Try to add a delay(selenium.wait 1000) before selecting the parent
window to see if it's the case.
I add a look in the documentation and found this command which selects the
original window instantiated by the browser :
wd.selectWindow "null"
You can also select the remaining window once the child window is closed:
hwnds= wd.WindowHandles
selenium.selectWindow hwnds(0)
> Shouldn't it be a high priority bug?
Priority is here to decorate and until proven that it diverts from the designed
behaviour, it's not a bug.
Bug tickets won't be visible by default after being closed whereas support
tickets will still be and will provide documentation for others.
> Execution is stuck as selenium object instance is set to null after closing
the child window
What makes you think the selenium object instance is null?
I may be wrong, but I'm certain that the Selenium instance is not null while
the script is running and the browser still opened.
Original comment by florentbr
on 9 Apr 2014 at 11:02
Original comment by florentbr
on 8 Sep 2014 at 5:40
Original issue reported on code.google.com by
nit.li...@gmail.com
on 8 Apr 2014 at 3:35