Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 等待窗口打开,然后再尝试切换到它_Java_Selenium_Testing_Ui Testing - Fatal编程技术网

Java 等待窗口打开,然后再尝试切换到它

Java 等待窗口打开,然后再尝试切换到它,java,selenium,testing,ui-testing,Java,Selenium,Testing,Ui Testing,我在测试中遇到了一个问题,我选择了一个按钮,然后切换到windwo,在我选择按钮后打开windwo,问题是我一直没有得到帧异常和越界异常 我的代码是: clickWithActions(driver, launchNote); sleepForTime(6000); Set<String> handles = driver.getWindowHandles(); List list = Arrays.asList(ha

我在测试中遇到了一个问题,我选择了一个按钮,然后切换到windwo,在我选择按钮后打开windwo,问题是我一直没有得到帧异常和越界异常

我的代码是:

        clickWithActions(driver, launchNote);
        sleepForTime(6000);
        Set<String> handles = driver.getWindowHandles();

        List list = Arrays.asList(handles.toArray());
        driver.switchTo().window(list.get(1).toString());
        sleepForTime(6000);
        driver.manage().window().maximize();
        driver.manage().window().setSize(new Dimension(1920, 1080));

        break;
clickWithActions(驱动程序、启动说明);
睡眠时间(6000);
Set handles=driver.getWindowHandles();
List=Arrays.asList(handles.toArray());
driver.switchTo().window(list.get(1.toString());
睡眠时间(6000);
driver.manage().window().maximize();
driver.manage().window().setSize(新维度(19201080));
打破
有什么方法可以让我等待此窗口首先出现,而不必等待很长时间吗?

这里有一个预期的等待条件,听起来很适合:

clickWithActions(driver, launchNote);

// wait for the number of windows to increase
new WebDriverWait(driver, 15).until(ExpectedConditions.numberOfWindowsToBe(2));
这里有一个听起来很合适的预期等待条件:

clickWithActions(driver, launchNote);

// wait for the number of windows to increase
new WebDriverWait(driver, 15).until(ExpectedConditions.numberOfWindowsToBe(2));

在执行
clickWithActions()
之前,您需要收集初始的WindowHandle,执行之后,您需要进行归纳。因此,您的有效代码块将是:

String first_handle = driver.getWindowHandle();
clickWithActions(driver, launchNote);
new WebDriverWait(driver,10).until(ExpectedConditions.numberOfWindowsToBe(2));
Set<String> allHandles = driver.getWindowHandles();
for(String winHandle:allHandles)
{
    if (!first_handle.equalsIgnoreCase(winHandle)
    {
    driver.switchTo().window(winHandle);
    }
}
String first_handle=driver.getWindowHandle();
单击操作(驱动程序、启动说明);
新的WebDriverWait(驱动程序,10)。直到(预期条件。窗口数为(2));
设置allHandles=driver.getWindowHandles();
for(字符串winHandle:allHandles)
{
if(!first_handle.equalsIgnoreCase(winHandle)
{
driver.switchTo()窗口(winHandle);
}
}

工具书类 您可以在以下内容中找到一些相关的详细讨论:


在执行
clickWithActions()
之前,您需要收集初始的WindowHandle,一旦执行,您需要对其进行归纳。因此,您的有效代码块将是:

String first_handle = driver.getWindowHandle();
clickWithActions(driver, launchNote);
new WebDriverWait(driver,10).until(ExpectedConditions.numberOfWindowsToBe(2));
Set<String> allHandles = driver.getWindowHandles();
for(String winHandle:allHandles)
{
    if (!first_handle.equalsIgnoreCase(winHandle)
    {
    driver.switchTo().window(winHandle);
    }
}
String first_handle=driver.getWindowHandle();
单击操作(驱动程序、启动说明);
新的WebDriverWait(驱动程序,10)。直到(预期条件。窗口数为(2));
设置allHandles=driver.getWindowHandles();
for(字符串winHandle:allHandles)
{
if(!first_handle.equalsIgnoreCase(winHandle)
{
driver.switchTo()窗口(winHandle);
}
}

工具书类 您可以在以下内容中找到一些相关的详细讨论: