1

我在这里面临一个有点奇怪的问题。当通过单击按钮打开第二个窗口时,我的整个脚本会挂起。此操作之后的下一行是 aSystem.out.println();并且在我手动关闭窗口之前它甚至不会在控制台中打印它。我已经添加了获取窗口句柄和切换的逻辑,但我怀疑代码是否达到了这一点。请在下面找到代码。

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();
    }
}
}

按下“继续”按钮后会出现问题。这将打开一个新窗口。System.out.println("Continue button clicked")在我手动关闭窗口之前,控制台中不会显示下一个。请帮忙。

PS:请原谅编码风格,这只是一个尝试。

4

1 回答 1

0

这是一个老话题,但请验证您的 IEDriverServer 版本,因为旧版本在管理模式对话框窗口时存在一些问题(一些问题已从 2.38 版修复,请参阅更新日志)。可能会有所帮助,我遇到了类似的问题,更新版本解决了这个问题。

于 2015-09-14T22:27:40.413 回答