窗口句柄的顺序 [英] Order of WindowHandles

查看:50
本文介绍了窗口句柄的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,WebDriver 似乎改变了 WindowHandles 的顺序.这会导致我们在某些情况下在获取错误后间歇性地关闭它们.

I'm encountering an issue where WebDriver seems to change the order of WindowHandles. This causes us to close the wrong one intermittently after getting them in some cases.

似乎发生的是先前建立的第一个窗口句柄作为后续句柄返回,这当然会导致我的逻辑关闭错误的.

What seems to happen is the previously established first window handle is returned as a subsequent handle, which causes my logic to of course, close the wrong one.

WebDriver 是否应该每次都以相同的顺序返回窗口句柄(从第一个打开的窗口到最后一个?).这是我最初的预期,但现在我不太确定.

Is WebDriver supposed to return the window handles in the same order every time (order of first opened window to last?). This is what I initially expected, but now I'm not so sure.

我还应该提到这个问题现在似乎只出现在 IE 中,但我不确定这是否是一个更普遍的问题.

I should also mention the problem seems to only occur in IE right now, but I'm not certain if this is a more generic issue.

这是我关闭活动窗口并切换回根窗口的方法.

Here is how I'm closing the active window and switching back to the root window.

public void Close()
        {
            //switch to latest window
            string windowName = string.Empty;
            if (_driver.WindowHandles.Count > 1)
            {
               //get 'root' window in list
                windowName = _driver.WindowHandles[0];
                _driver.Close();
                _driver.SwitchTo().Window(windowName);
            }
            else
            {
                _driver.Close();
            }
        }

我们使用的是 WebDriver 2.45(C# 绑定,32 位 IEDriver).如果有一种方法可以关闭 C# 绑定中的活动窗口,这也很可能解决此问题.

We're on WebDriver 2.45 (C# bindings, 32-bit IEDriver). If there is a method to close the active window in the C# bindings that would most likely solve this issue as well.

推荐答案

根据我的理解,这个弹出窗口处理程序是完全无序的.我记得在 SO 上有过同样的对话,幸运的是 JimEvans(Selenium 的贡献者之一)插话并澄清了几个因素.我阅读了 Selenium .NET 绑定的 PopupWindowFinder 并发现该类可以让您的生活更轻松.API 位于此处.然而,整个订单问题处理起来非常复杂和痛苦.请参阅主题.只是不想重新发明轮子.

This pop up window handler is entirely unordered as per my understanding. I remember having same conversation on SO and luckily JimEvans(one of the contributors of Selenium) chimed in and clarify few factors. I read about the PopupWindowFinder of Selenium .NET bindings and found that class can make your life lot easier. API is here. However, the whole order issue is entirely complex and painful to deal with. See this thread. Just don't want to reinvent the wheel.

这篇关于窗口句柄的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆