7Gabriel / selenium-vba

Automatically exported from code.google.com/p/selenium-vba
0 stars 0 forks source link

driver.getAllWindowTitles fail #96

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi Florent,

can you please help. getting error with below line of codes.

     driver.Wait 2000
     Handle = driver.WindowHandles
     driver.Wait 2000
     t = driver.getAllWindowTitles   ''ERROR <GetallWidowTitles> failed
     driver.selectWindow "null"

    For X = LBound(t) To UBound(t)
    If t(X) = "ABC" Then
     driver.switchToWindow Handle(X)
     driver.switchToDefaultContent
    End If
    Next

Original issue reported on code.google.com by vishal.a...@gmail.com on 19 Sep 2014 at 10:10

Attachments:

GoogleCodeExporter commented 8 years ago
I couldn't reproduce your issue.
Can you provide a failing example on a public web site?

Original comment by florentbr on 3 Oct 2014 at 2:07

GoogleCodeExporter commented 8 years ago
Hi Florent,

I have attached the code for your reference.

The issue start where I get Alert message after clicking submit button on 3rd 
Popup.

It seems at that time driver is referring to popup window 3rd which get close 
where as the Alert generated on popup window 2.

if I remove below line of code then I get error "Method <getAllWindowTitles> 
falied!"

driver.switchToAlert(20000).Accept

could you please help.  Not sure if I am using the correct approach.

Thanks

Original comment by vishal.a...@gmail.com on 7 Oct 2014 at 9:56

Attachments:

GoogleCodeExporter commented 8 years ago
It looks like you need to set the window once it's been closed.
Have you tried to use index instead of a loop ?
 wd.switchToWindow 0, 5000   'first window
 wd.switchToWindow 2, 5000   'third window
 wd.switchToWindow -1, 5000  'last window
 wd.switchToWindow "message", 5000  'window.name = message

Within your code :
'Main window appears
driver.findElementByName("UserName").Clear().SendKeys "ABC"
driver.findElementByName("Password").Clear().SendKeys "XXX"
driver.findElementById("btLoginId").Click
...
'Popup 1 appears
driver.switchToWindow 1, 5000
...
'Popup 2 appears
driver.switchToWindow 2, 5000
...
'Popup 3 appears    
driver.switchToWindow 3, 5000
...
'Popup 3 closes and alert appears
driver.switchToWindow 2, 5000
driver.switchToAlert(20000).Accept

You could also create a function to select the window by title:
Sub switchToWindow(ByRef wd As Webdriver, title As String)
    handles = wd.WindowHandles
    For Each hdl In handles
        If wd.switchToWindow(hdl).title = title Then Exit Sub
    Next
    Err.Raise -1, Description:="Window not found: " & title
End Sub

Original comment by florentbr on 9 Oct 2014 at 6:34