leochabi / selenium-vba

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

switchToWindow fail #103

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi Florent,

Below line of code get failed.

driver.switchToWindow "XXXX", 5000   'error no window found. timeout

however,if I try below it get executed.  could you please help.

title = driver.getAllWindowTitles              

    driver.Wait 2000
   For X = LBound(title) To UBound(title)

    If title(X) = "XXXX" Then
     driver.switchToWindow Handle(X)
     driver.switchToDefaultContent
     driver.Wait 200
    End If
    Next

Thanks

Original issue reported on code.google.com by rohitkbh...@gmail.com on 8 Oct 2014 at 10:24

GoogleCodeExporter commented 8 years ago
The switchToWindow is a Selenium 2 command and it expects either a zero based 
index, a window name, a handle, but not a title.
 wd.switchToWindow 0   'first window
 wd.switchToWindow 2   'third window
 wd.switchToWindow -1  'last window
 wd.switchToWindow "message"  'window named message

You should see the difference in your browser's console with these JS commands:
window.name
window.title

Another solution is loop over the windows until you find the right 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

The getAllWindowTitles is an old Selenium 1 command and the equivalent to 
switchToWindow in Selenium 1 is selectWindow.
It may work with the both the name and title:
http://release.openqa.org/selenium-remote-control/0.9.2/doc/dotnet/Selenium.Defa
ultSelenium.SelectWindow.html

Original comment by florentbr on 9 Oct 2014 at 5:51

GoogleCodeExporter commented 8 years ago
Thanks Florent,

Though it working with the 2nd solution you provided i.e. loop over all the 
windows.

Not sure but switchtowindow is not accepting windows Index. could you please 
check.

wd.switchToWindow 2,5000   ' error not window found. timeout

Original comment by rohitkbh...@gmail.com on 9 Oct 2014 at 12:06

GoogleCodeExporter commented 8 years ago
Yes i'm sure it's working with index, unless you're not using the last 
version(1.0.20)
The reason you're getting this error must be that there weren't 3 windows 
opened during the session or that the third window took more than 5 seconds to 
appear.

Original comment by florentbr on 9 Oct 2014 at 12:37

GoogleCodeExporter commented 8 years ago
ah....I think am not using the latest version.

Thanks again. (:

Original comment by rohitkbh...@gmail.com on 9 Oct 2014 at 1:11

GoogleCodeExporter commented 8 years ago
Hi Florent,

I have install this s/w on another system.  Everytime I start my system I get 
this error.

can u plz check.

Thanks
Rohit Bahtia

Original comment by rohitkbh...@gmail.com on 22 Oct 2014 at 10:40

Attachments:

GoogleCodeExporter commented 8 years ago
SeleniumVBA changes the default VBS console runner to an enhanced one.
It is an options at the end of the installation process.
Unfortunately for you it seems that you have a VBS file running at the start-up 
and this VBS contains a command that is not supported.
First you should check that this VBS script(regsetting.vbs) is not a malware.

Then you can restore the default console runner:
  Open Folder Option > File Types > VBS 
and change the default association to :
  "Microsoft Console Based Script Host"
or select C:\WINDOWS\system32\wscript.exe

Original comment by florentbr on 22 Oct 2014 at 11:18