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.