3

Is it possible to work on multiple windows using selenium, when I searched on the net, there are only explanations and codes available for Selenium2 webdriver version.

For the normal selenium I can't find any info on it. So is there a way multiple window operations be performed in selenium + java , if yes, how can it be achieved?

4 Answers 4

2

If, by "multiple windows", you mean "separate browsers", then the answer is yes, but differently from Ardesco's answer. In this case, you need to start multiple Selenium browser instances, and then use each one as a separate browser. We do exactly this to test the online-chat feature of our product, with each browser logged in as a different user and driving them to talk to each other.

0

Buh... forgive me for only responding in terms of theory and not in terms of practice, because I understand the concepts underlying what you're trying to do, but lack directly applicable experience with either set of the Selenium2 webdrivers.

With respect to what you're trying to achieve, however, it seems comparable to any asynchronous set of operations on multiple internet windows and therefore should be something you can handle thusly regardless of which programming language or tool set is employed.

Just glancing over the API documentation, it appears that the tools used for these types of events are the "andWait" / "waitFor" methods: http://seleniumhq.org/docs/02_selenium_ide.html#the-andwait-commands

Since you didn't provide much detail as to WHAT you want to do with multiple windows, let's assume for a moment that your application wants to play tic-tac-toe in two windows, and one of each window is responsible for playing the side in question.

So. once you have successfully created a Selenium instance that can do ONE side of what you're looking to accomplish (check out http://seleniumhq.org/docs/03_webdriver.html for more webdriver docs -- I'm seeing everything you need there to get most jobs done), it simply becomes a matter of keeping both sides in sequence. You can run both jobs simultaneously and have them report back to a service daemon you create specifically for this purpose, tracking based on time stamps or other sequential data YOU provide arbitrarily to keep the events of each browser window "in step" with the other one.

Again, I can only respond in basic theory because of the limited amount of information I have on your project and my limited experience with Selenium; however, I hope this helps.

0

If I'm reading your question correctly you are asking if you can test multiple windows using the Selenium RC API. If so the answe is Yes.

Use selenium.selectWindow("Window[Titel/Id/Name]") to switch to different windows. This must be a window that has been opened by the browser controlled by Selenium.

You can get a list of available windows using one of the following:

selenium.getAllWindowTitles();
selenium.getAllWindowIds();
selenium.getAllWindowNames();
0

You can try the below code,

public class TestNaukri {

    @Test
    public void TestPopUp() throws InterruptedException{
    // Open browser
    WebDriver driver=new FirefoxDriver();

    // Maximize browser
    driver.manage().window().maximize();

    // Load app
    driver.get("http://www.naukri.com/");

    // It will return the parent window name as a String
    String parent=driver.getWindowHandle();

    // This will return the number of windows opened by Webdriver and will return Set of St//rings
    Set<String>s1=driver.getWindowHandles();

    // Now we will iterate using Iterator
    Iterator<String> I1= s1.iterator();

    while(I1.hasNext())
    {

       String child_window=I1.next();

    // Here we will compare if parent window is not equal to child window then we            will close

    if(!parent.equals(child_window))
    {
    driver.switchTo().window(child_window);

    System.out.println(driver.switchTo().window(child_window).getTitle());

    driver.close();
    }

    }
    // once all pop up closed now switch to parent window
    driver.switchTo().window(parent);

    }
    }
1
  • While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value.
    – alecxe
    Mar 15, 2018 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.