1

I tried using window-handles, Alerts and also i tried without switching the window. But none of the idea worked for me. Once i select the element a new browser sub-window opens up. Now the control is on the new sub-window which i cannot detect at all. Need help. Before the action which opens this sub-window i can print to console but not after that. Also i tried JavaScriptExecutor but it didn't work too.

I am putting the screen shot of the window how it looks like. You can see the sub window is new but it is opened inside the main window and the control is totally on it.

This is how it looks

Rupesh Shinde
  • 1,933
  • 12
  • 22

1 Answers1

1

Here, I have used Robot class to interact with the dialog box. No need to switch windows. Try the below code. Hello is the data to enter:

    StringSelection data_to_enter= new StringSelection("Hello");
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(data_to_enter, null);

    Robot robot = new Robot();
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);
Subh
  • 4,354
  • 1
  • 13
  • 32
  • Oh...no...Its still sticked at the same point. I wonder lets try to print some thing before we take control of another window.. – Rupesh Shinde Nov 22 '14 at 16:34
  • True enough.. Let me know how it goes with print before clicking, and print after clicking. – Subh Nov 22 '14 at 16:36
  • Before clicking it prints but after Clicking it does not – Rupesh Shinde Nov 22 '14 at 16:48
  • After clicking on **New Access Level**, give a sleep time of say 5 seconds using `Thread.sleep(5000)` **just before the _for loop_**. It's not feasible, I know. But just in case let's see if it needs some more time to detect the new window, that is. – Subh Nov 22 '14 at 17:01
  • Also, @RupeshShinde, take a look at this link for getting the new window's name. [http://release.openqa.org/selenium-remote-control/0.9.2/doc/dotnet/Selenium.DefaultSelenium.SelectWindow.html](http://release.openqa.org/selenium-remote-control/0.9.2/doc/dotnet/Selenium.DefaultSelenium.SelectWindow.html) . It might help in fetching the new window's name and switching. – Subh Nov 22 '14 at 17:07
  • When we open a new window , the new window can be either a independent of the main window or it can be a pop-up window inside a main window but not an alert. so for a pop up window inside the main window is their any other way we can appraoch? – Rupesh Shinde Nov 23 '14 at 09:30
  • In that case **there is no need to switch windows**.. Try accessing the field directly and input the data because, it is a part of main window after all. – Subh Nov 23 '14 at 09:39
  • This is really making me crazy and time consuming...I have uploaded new image and modified my question into more simple one. Please have a look if you think if we left any stone unturned. – Rupesh Shinde Nov 23 '14 at 15:19
  • I have an idea to solve this problem using **Robot class**. Before that just check 2 things manually. **1-** When the new window opens, is the focus (means the cursor) blinking on the textfied. If not, then how many times do you have to press **"TABS KEY"** to get the focus there ? **2-** After filling data if you press **"ENTER KEY"** does the data gets saved and window closes or do you have to press **"TABS KEY" again to move cursor to the **"OK"** button and then press **"ENTER or SPACE KEY"** to save the data and close the window? – Subh Nov 23 '14 at 15:46
  • Yes the focus blinks on the main screen..if we any enter any string and hit enter button the it gets saved and window disappears. – Rupesh Shinde Nov 23 '14 at 16:07
  • I tried it after i click on the element which opens the sub-window Robot r = new Robot(); r.setAutoDelay(250); r.keyPress(KeyEvent.VK_D); // C r.keyRelease(KeyEvent.VK_D); r.keyPress(KeyEvent.VK_ENTER); r.keyRelease(KeyEvent.VK_ENTER); Still the same , No error message – Rupesh Shinde Nov 23 '14 at 16:16
  • Comments are not for extended discussion; this conversation has been [moved to chat](http://chat.stackoverflow.com/rooms/65470/discussion-on-answer-by-subh-unable-to-switch-to-browser-window-which-is-inside). – Taryn Nov 23 '14 at 16:17
  • @RupeshShinde: Check the code above and reply me in the chat window please. – Subh Nov 23 '14 at 16:52
  • @Subh: Tried all the attempts but still no success. Its 3rd day in the row. Here are some wondefull conclusions we made till now. 1. Its a ModalDialog Box . 2. The control is not passing from parent window to ModalDialog box. 3. By using Robot class Tab atleast we can get errors but not control of ModalDialog Box. Here are the interesting sites i have came across.. http://seleniumdeal.blogspot.in/2010/04/working-with-modal-dialogs-and-selenium.html also you can go through http://stackoverflow.com/questions/14098679/how-to-switch-from-main-window-to-popup-window ...Way to go... – Rupesh Shinde Nov 24 '14 at 10:39
  • Thanks, those are very useful infos.. :) I have one last way to deal with your problem then. [Please join this chat](http://chat.stackoverflow.com/rooms/65470/discussion-on-answer-by-subh-unable-to-switch-to-browser-window-which-is-inside). I can help you after that. Continuing the discussion here won't be good. – Subh Nov 24 '14 at 14:01
  • @Subh : It worked for me. Thanks for your Valuable efforts. Finally we are able to handle ModalDialog Box using Robot class. – Rupesh Shinde Nov 24 '14 at 16:10