本文介绍了Opera-driver.WindowHandles返回错误的计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的情况下,我正在验证是否单击链接可以导航到另一个页面(验证页面标题). IE FF chrome 返回预期的2,但 Opera 返回4.我没有其他Opera实例在运行测试时打开.单击链接,打开所需的页面,但WindowHandles返回4.

In my scenario, I'm verifying whether clicking on a link navigates to another page (verifying for the page title). IE, FF and chrome return 2 as expected but Opera returns 4. I didn't have any other Opera instances opened at the time of running tests. It clicks on the link and required page is opened but WindowHandles returns 4.

代码:

string BaseWindow = Drivers._driverInstance.CurrentWindowHandle;
Drivers._driverInstance.SwitchTo().Frame(Drivers._driverInstance.FindElement(By.ClassName("iframe-fix")));
if (Drivers._driverInstance.GetType().Name.ToString() == "InternetExplorerDriver")
{
    IJavaScriptExecutor js = (IJavaScriptExecutor)Drivers._driverInstance;
    js.ExecuteScript("arguments[0].click();", Drivers._driverInstance.FindElement(By.LinkText("Professional Services.")));
}
else
{
    Drivers._driverInstance.FindElement(By.LinkText("Professional Services.")).Click();
}
    System.Collections.ObjectModel.ReadOnlyCollection<string> handles = Drivers._driverInstance.WindowHandles;
    if (handles.Count == 2)
    {
      foreach (string handle in handles)
      {
         if (handle != BaseWindow)
         {
            string title = Drivers._driverInstance.SwitchTo().Window(handle).Title;
            Assert.AreEqual("title of the page", Drivers._driverInstance.Title);
          }
      }
     }
    else
    {
        Assert.Fail("WindowHandles returns " + handles.Count + " instead of 2");
    }
Drivers._driverInstance.SwitchTo().Window(BaseWindow);

有人可以建议Opera为何返回4而不是2.

Can someone suggest why Opera returns 4 instead of 2.

谢谢.

推荐答案

Opera驱动程序未返回正确数量的句柄.已经向项目报告了此问题,但是似乎不再维护该项目:

The Opera driver doesn't return the right number of handles. This issue has already been reported to the project but it seems that the project is no longer maintained:

https://github.com/operasoftware/operachromiumdriver/issues/15

这篇关于Opera-driver.WindowHandles返回错误的计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 13:54