从弹出窗口切换回主窗口后的操作超时

时间:2015-03-20 08:34:41

标签: php selenium-webdriver popup webdriver phpunit

我正在使用带有Selenium2扩展名的PHPUnit。

我打开一个弹出窗口,输入数据并点击提交按钮 - 之后弹出窗口关闭。

稍后我会切换回主窗口 - 所有这些都完美无瑕。但在切换回来之后,我的测试没有执行其他步骤,并且测试失败并显示以下错误消息:

PHPUnit_Extensions_Selenium2TestCase_NoSeleniumException: Error connection[28] to http://localhost:4444/wd/hub/session/d6977d2b-76ac-4754-9a08-5119413b0965/element/4/submit: Operation timed out after 60004 milliseconds with 0 bytes received

为了完整起见,代码:

$windowHandles = $this->windowHandles();

$this->window($windowHandles[1]);

$this->byCssSelector('input[id=email]')->value($fbUsername);
$this->byCssSelector('input[id=pass]')->value($fbPassword);
$this->byCssSelector('input[id=u_0_1]')->submit();

$this->window($windowHandles[0]);

我错过了一些必要的步骤吗?我必须等待什么吗?任何指针都会有所帮助。

3 个答案:

答案 0 :(得分:2)

@akluth,一个错误是发现并将被修复。您可以查看更多信息here。我正在等待新版本。

答案 1 :(得分:0)

我不是PHP人,但我希望以下代码能为您提供一些如何处理此问题的建议。注意:以下是C#代码

//You probably missing this the concept of handling current and original handle
string currentHandle = driver.CurrentWindowHandle;
ReadOnlyCollection<string> originalHandles = driver.WindowHandles;

// Cause the pop-up to appear
driver.FindElement(By.XPath("//*[@id='webtraffic_popup_start_button']")).Click();

// WebDriverWait.Until<T> waits until the delegate returns
// a non-null value for object types. We can leverage this
// behaviour to return the pop-up window handle.
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
string popupWindowHandle = wait.Until<string>((d) =>
{
    string foundHandle = null;

    // Subtract out the list of known handles. In the case of a single
    // pop-up, the newHandles list will only have one value.
    List<string> newHandles = driver.CurrentWindowHandles.Except(originalHandles).ToList();
    if (newHandles.Count > 0)
    {
        foundHandle = newHandles[0];
    }

    return foundHandle;
});

driver.SwitchTo().Window(popupWindowHandle);

// Do whatever you need to on the pop-up browser, then...
driver.Close();
driver.SwitchToWindow(currentHandle);

因为,你说所有这一切都完美无瑕。但是在切换回来后,我的测试没有执行其他步骤并且测试失败 因为你还没有正确切换回原来的窗口句柄。

此代码是从here复制粘贴的 感谢@JimEvans解释这个过程。

答案 2 :(得分:-1)

看起来您的浏览器已升级。您需要相应地更新您的selenium库。

相关问题