none
How can I visibly switch from chrome to firefox second window? RRS feed

  • Question

  • I am using 2 browsers chrome and firefox. There are two windows in firefox. The second windows open on a button click on the first firefox window. I performed some action in Chrome and then performed
    driver.SwitchTo().Window(Firefox.WindowHandles.Last());

    This moved to firefox second window but that window does not appear. So I cannot see whether actions are performed on the firefox second window or not. How can I visibly switch to firefox second window from chrome?

    I am using C# Mstest seleniumwebdriver.

    Monday, June 1, 2020 12:07 PM

Answers

  • Hi Amna,

    Thanks for the feedback.

    You could try to add this code line before you write the “switch to…” code line to switch to the Firefox second window and minimize the chrome window to check if the Firefox second window is visible.

    driver.Manage().Window.Minimize();

    >> Should I maximize the Firefox second window or not?

    ## Of course, you can maximize the Firefox second window.

    Feel free to let me know if you have any update.

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, June 4, 2020 9:04 AM
  • Hi Amna,

    Thanks for detailed explanation.

    Perhaps you can try to use XXX.Minimize() method to minimize the window for seeing the second window of Firefox, and use XXX.Maximize() method to re-view the chrome window. Of course, you can minimize or maximize any of the window to choose which window you’d like to view.(I think re-maximize will fix the resize issue)

    The codes may like this:

      //Perform something on First Window(Firefox)
      //Trigger and open the Second Window(Firefox), then perform some actions
      //switch to chrome window, here you may write
      driver.Manage().Window.Maximize(); //and you can just see chrome window
                
      .... //perform some actions for chrome window
    
      driver.Manage().Window.Minimize(); //minimize the chrome window before switch to second window of Firefox
    
      //switch to second window of Firefox
    
      driver.Manage().Window.Maximize(); //maximize the second window of Firefox
    
      //perform some actions for second window of Firefox
    
      //try to minimize the second window of Firefox and re-maximize any other windows which you'd like to view with following codes
      driver.Manage().Window.Minimize();//(optional)
      ................//(optional)
      driver.Manage().Window.Maximize();//(optional)

    Feel free to contact me.

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 9, 2020 8:01 AM

All replies

  • Hi Amna,

    Welcome to MSDN forum.

    I may misunderstand you, but it seems the second window of firefox doesn’t open correctly.

    >> This moved to firefox second window but that window does not appear.

    ## Normally, after clicking button the new window will open and appear, from the codes you shared with me, I think it’s correct and if the second window really opens, the test will be able to move to the second window.

    ## So, I think the issue is more related to the codes that you used to perform a button click. You may need to check the codes of “button click” and make sure that the second window of firefox really opens. You could use “Thread.Sleep(XXXX)” to slow down the execution and see the result.

    ## I think the related codes should be like this: driver.FindElement(By.XXXXX).Click()

    In addition, if you just try to switch window right after clicking the button, will the second window appear/open and perform well?

    Any feedback will be expected.

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, June 2, 2020 7:50 AM
  • I am using chrome and Firefox. Both chrome and Firefox windows are open.

    First Actions are performed on Firefox and a second window is opened on a button click on firefox first window. Second window is also Firefox. I performed some action on that second window and then with 

    driver.SwitchTo().Window(Firefox.WindowHandles.Last());
    I moved to chrome window it is visible that was already opened. I performed actions in chrome and then write again
    driver.SwitchTo().Window(Firefox.WindowHandles.Last());
    It moved to Firefox second window but it didn't appear. Actions are performed on second window again as test case is passed successfully. only issue is visibility when i move from chrome to Firefox second window.
    Tuesday, June 2, 2020 9:13 AM
  • Hi Amna,

    Thanks for your feedback.

    If you try to add “Thread.Sleep(3000);” and warp the “driver.SwitchTo().Window(Firefox.WindowHandles.Last());” code line like this:

    Thread.Sleep(3000);
    driver.SwitchTo().Window(Firefox.WindowHandles.Last());
    Thread.Sleep(3000);

    Will the Firefox second window be visibility this time?

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, June 3, 2020 5:36 AM
  • Thanks for the help but It didn't work. Is there any other way to do it?
    Wednesday, June 3, 2020 7:42 AM
  • Hi Amna,

    Thanks for the feedback.

    After researching more, I consider if the second window is hiding behind the chrome window which make it invisible? Maximize the window may lead to this issue.

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, June 3, 2020 10:06 AM
  • Should I maximize the Firefox second window or not? If Windows are maximized how can we show the windows on below command
    driver.SwitchTo().Window(Firefox.WindowHandles.Last());

    ?

    Wednesday, June 3, 2020 12:04 PM
  • Hi Amna,

    Thanks for the feedback.

    You could try to add this code line before you write the “switch to…” code line to switch to the Firefox second window and minimize the chrome window to check if the Firefox second window is visible.

    driver.Manage().Window.Minimize();

    >> Should I maximize the Firefox second window or not?

    ## Of course, you can maximize the Firefox second window.

    Feel free to let me know if you have any update.

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, June 4, 2020 9:04 AM
  • The browser is minimized with this 
    driver.Manage().Window.Minimize();
    
    But it is resized too. how can I do that chrome just minimized but not resized.
    Thursday, June 4, 2020 10:16 AM
  • Hi Amna,

    Thanks for your feedback.

    I am a little confused about “resized”, could you share me with some screenshots or details?

    Looking forward to hearing from you.

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 5, 2020 10:01 AM
  • I am not able to attach the screenshot. Resize means the window was on full screen and while minimizing the window gets resized like instead of whole screen view it was a little small than the whole screen.
    Friday, June 5, 2020 12:07 PM
  • Hi Amna,

    Thanks for detailed explanation.

    Perhaps you can try to use XXX.Minimize() method to minimize the window for seeing the second window of Firefox, and use XXX.Maximize() method to re-view the chrome window. Of course, you can minimize or maximize any of the window to choose which window you’d like to view.(I think re-maximize will fix the resize issue)

    The codes may like this:

      //Perform something on First Window(Firefox)
      //Trigger and open the Second Window(Firefox), then perform some actions
      //switch to chrome window, here you may write
      driver.Manage().Window.Maximize(); //and you can just see chrome window
                
      .... //perform some actions for chrome window
    
      driver.Manage().Window.Minimize(); //minimize the chrome window before switch to second window of Firefox
    
      //switch to second window of Firefox
    
      driver.Manage().Window.Maximize(); //maximize the second window of Firefox
    
      //perform some actions for second window of Firefox
    
      //try to minimize the second window of Firefox and re-maximize any other windows which you'd like to view with following codes
      driver.Manage().Window.Minimize();//(optional)
      ................//(optional)
      driver.Manage().Window.Maximize();//(optional)

    Feel free to contact me.

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 9, 2020 8:01 AM