【问题标题】:Operation timeout after switching back from popup window to main window从弹出窗口切换回主窗口后操作超时
【发布时间】:2015-05-23 14:49:31
【问题描述】:

我正在使用带有 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]);

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

【问题讨论】:

  • 只是一个猜测,虽然在 phpunit 上不起作用,你可以试试$this->window($this->windowHandles());

标签: php selenium-webdriver popup webdriver phpunit


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    我不是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 解释这个过程。

    【讨论】:

      【解决方案3】:

      您的浏览器好像升级了。您需要相应地更新您的 selenium 库。

      【讨论】:

      • 你这个猜测的依据是什么?
      • @SiKing 当我的 FF 浏览器由于启用了自动更新而升级时,我可能会遇到“操作超时”的情况。在那种情况下,我曾经卸载并安装以前的版本/升级我的硒库。大多数时候它解决了我的问题。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多