1

I am facing a bit strange issue here. My entire script hangs when a second window is opened by clicking a button. The very next line after this action is a System.out.println(); and it doesn't even print that in the console until i manually close the window. I have added the logic to get the window handles and switch, but I doubt the code even reaches that point. Please find the code below.

import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerDriverService;
import org.openqa.selenium.Keys;
import java.util.Iterator;

public class ACHClearTransfer {
public static void main(String[] args){
System.setProperty("webdriver.ie.driver","C:/Progra~1/IEDriverServer.exe");
    System.setProperty("webdriver.ie.driver.extractpath", "C://Progra~1");  
    WebDriver driver = new InternetExplorerDriver();
    try{
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.get("https://XXXXXXXX.com"); 
        Thread.sleep(3000);
        String parentWindowHandler = driver.getWindowHandle();
        System.out.println("parent window handler is "+parentWindowHandler);
        driver.findElement(By.xpath("//input[@type='text' and @name='tbUsername']")).sendKeys("********");
        driver.findElement(By.xpath("//input[@type='password' and @name='tbPassword']")).sendKeys("*******");
        System.out.println("Entered ID and password");
        driver.findElement(By.xpath("//span[text()='Log in']")).click();
        driver.findElement(By.xpath("//input[@type='password' and @name='challengeAnswer']")).sendKeys("*******");
        driver.findElement(By.xpath("//span[text()='Continue']")).click();
        System.out.println("Continue button clicked");
        Thread.sleep(5000);
        System.out.println("Thread sleep completed.");
        String subWindowHandler = null;
        try{
            System.out.println("Inside try");
            Set<String> handles = driver.getWindowHandles(); // get all window handles
            System.out.println("All window handles "+handles);

            for(String handle:handles){
                if(!parentWindowHandler.equals(handle)){
                    subWindowHandler = handle;
                }
            }                  
        }
        catch(Exception e){
            e.printStackTrace();
        }

        driver.switchTo().window(subWindowHandler);
        System.out.println(driver.getTitle());
        driver.close();
        Thread.sleep(2000);

        driver.switchTo().window(parentWindowHandler); 
        System.out.println("Back in parent window");
        System.out.println(driver.getTitle());
        Thread.sleep(2000);

        driver.findElement(By.xpath(".//*[@id='navAcc']/a")).click();
        driver.findElement(By.xpath(".//*[@id='portfolioDepositsScheduledTransfers']/a")).click();

        boolean temp = driver.findElement(By.xpath("(//a[text()='Delete'])[1]")).isDisplayed();

        while(temp==true){
            driver.findElement(By.xpath("(//a[text()='Delete'])[1]")).click();
            Thread.sleep(2000);
            temp = driver.findElement(By.xpath("(//a[text()='Delete'])[1]")).isDisplayed();

        }
    }
    catch(Exception e){
        e.printStackTrace();
    }
    finally{
        driver.quit();
    }
}
}

Issue happens after pressing the 'Continue' button. This opens up a new window. The next System.out.println("Continue button clicked") is not displayed in the console until I close the window manually. Please help.

PS: Please pardon the coding style, this is just a try.

Nirmal
  • 1,229
  • 1
  • 15
  • 31
Amith
  • 89
  • 2
  • 11
  • *but I doubt the code even reaches that point* did you try with a debug point at the place where you added window handles and switch? – Nirmal Apr 14 '15 at 17:10
  • I have tried. The code is not reaching any break points that I have added after //span[text()='Continue'] button. All I can see in the Debug view is 4 threads running. 2 are Daemon and other another is Thread 1 and one more thread with stack 'Thread [Forwarding clickElement on session a32e1c36-0fbe-404b-b009-4bd5aef3b7ed to remote] (Running) ' . Things just hang there, nothing happens after this. – Amith Apr 14 '15 at 18:24
  • There is no reason why println would not print. My guess would be statement clicking on continue is not able to execute properly. Try print before and move your try block right after clicking continue.. see example here http://stackoverflow.com/questions/19112209/how-to-handle-the-new-window-in-selenium-webdriver – starthis Apr 14 '15 at 21:31
  • No change. Any i thing i print before clicking Continue is working fine, nothing after that. – Amith Apr 16 '15 at 15:43
  • I am trying to understand what happens when you manually do what you have coded. After you enter the login credentials and click continue a popup window opens? You are saying that "Continue button clicked" is not being printed out to the console. Right? – LINGS Aug 26 '15 at 16:09

1 Answers1

0

This is an old topic but please verify your IEDriverServer version, as old versions had some problems when managing modal dialog windows (some problems were fixed from version 2.38, please refer to changelog). Probably it would help, i was having a similar problem and updating the version solved the issue.