本文介绍了如何获取硒中已打开的IE浏览器句柄?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经打开了一个带有某些URL的IE浏览器.之后,我运行下面的代码,这将打开另一个IE浏览器.但是在下面的代码中它只给我一个窗口句柄.是否可以获取以前打开的IE浏览器句柄?
I have one already opened IE browser , with some url. After this, I Run below code which will open another IE browser. however it gives me only one window handle in below code.Is it possible to get previously opened IE browser handle ?
IWebDriver IEdriver = new InternetExplorerDriver();
IReadOnlyCollection<String> browsers = IEdriver.WindowHandles;
foreach (String item in browsers)
{
IEdriver.SwitchTo().Window(item);
String url = IEdriver.Url;
}
推荐答案
我认为这是您要寻找的:
I think this is what you're looking for:
String winHandleBefore = driver.getWindowHandle();
//Do whatever operations you have to do
for(String winHandle : IEdriver.getWindowHandles()){
IEdriver.switchTo().window(winHandle);
}
这篇关于如何获取硒中已打开的IE浏览器句柄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!