TestProject Forum

Switch to New Window

Hi Everyone,

This is about handling a new window at runtime. I have a script created and during creating the script opens a new tab and I am using these two steps:
1- Get Window handles (not sure what it does, I am sending the output to a variable but it returns all the open tabs of the window separated by comma eg [“CDWindows-12125122”,:CDwindows-234455"]
2-- Switch to window “2” - using index

The issue here is when I am creating the script and debugging the code it is working fine and I am able to switch to the third tab using index value 2 but at the time of execution it is opening a new window and my script fails. I tried to protect it from the browser level but did not work

Is there a way that the script can switch to a window based on the Title of the Window?

Thanks for your prompt reply,

Hi @sharpat8
As you can see here:

The same tabs on different runs do not contain the same value, for moving between tabs in a specific index please use the action “switch to window” if you want to verify you are on the correct window you can check the URL or use any other method but if you are running the same flow switching to a specific window should be the same.

image

Note that the index starts at 0 (first tab)

1 Like

Hi Amit,
I am using Switch to Window but it is not working for me :frowning:

Can you provide more details?

@Amit.Lacher I am now experiencing this issue and would like to know what work around you all came up with. During execution, my app opens a new window, (not a new tab) and I am wondering how to set focus on the new window.

Hi @phai , can you provide an URL example, steps to reproduce, or share your test with amit.lacher@testproject.io?