简体   繁体   English

Selenium 2.32,Java 1.6.0_07,IE Webdriver(32和64位),IE9-getWindowHandles仅返回一个浏览器

[英]Selenium 2.32, Java 1.6.0_07, IE Webdriver (32 and 64 Bit), IE9 - getWindowHandles returns only one browser

I am using Selenium 2.32, Java JDK 1.6.0_07, IE9 with Windows 7. Here is the problem 我正在Windows 7中使用Selenium 2.32,Java JDK 1.6.0_07,IE9。这是问题所在

  1. When i use IE WebDriver 32 Bit and click on a link which opens a new browser containing PDF, the PDF is opened in the browser itself which is fine, but the new browser is not identified when i use driver.getWindowHandles(). 当我使用IE WebDriver 32位并单击一个链接以打开一个包含PDF的新浏览器时,会在浏览器本身中打开PDF,这很好,但是当我使用driver.getWindowHandles()时无法识别新的浏览器。 It always returns only the parent window. 它总是只返回父窗口。 When i use the same code with IE8, it works perfectly fine and i am able to get the URL of the new browser. 当我在IE8中使用相同的代码时,它可以很好地工作,并且我能够获取新浏览器的URL。

  2. I thought since it is Windows 7 and IE9, i should use IE Webdriver 64 bit and so i used IE Webdriver version 2.32.3 (64 Bit). 我以为是Windows 7和IE9,我应该使用IE Webdriver 64位,因此我使用IE Webdriver 2.32.3版(64位)。 With this webdriver, when i click on the link, the new browser pops up but the PDF is not opened in the browser and instead it is opened as a separate PDF file. 使用此网络驱动程序,当我单击链接时,会弹出新的浏览器,但未在浏览器中打开PDF,而是将其作为单独的PDF文件打开。 Even in this case, the new browser is not identified and driver.getWindowHandles() returns only one browser. 即使在这种情况下,也不会标识新的浏览器,并且driver.getWindowHandles()仅返回一个浏览器。

Not just the PDF browsers but also the normal browsers are not returned by driver.getWindowHandles() driver.getWindowHandles()不仅不会返回PDF浏览器,而且不会返回普通浏览器。

I am using a wait of 10 seconds for the new browser to load and so the there is no load/sync issue. 我正在等待10秒钟,以便加载新的浏览器,因此没有加载/同步问题。 I want to identify the new browser and get the URL of the new browser. 我想识别新浏览器并获取新浏览器的URL。 Please help. 请帮忙。

The problem here is that you are making things too complicated. 这里的问题是您使事情变得太复杂了。 From your comments, it does not seem you are doing things the "typical" and "recommended" way. 从您的评论看来,您似乎并没有以“典型”和“推荐”的方式来做事情。 If you are following advice, then you are doing it the slightly harder route. 如果您遵循建议,那么您的做法会稍微困难一些。 My advice is still to simplify further. 我的建议仍然是进一步简化。

If I were to guess on your issue though: I notice that you say you are using "IEDriverServer". 但是,如果我要猜测您的问题:我注意到您说您正在使用“ IEDriverServer”。 That tells me that you may be improperly using WebDriver. 这告诉我您可能未正确使用WebDriver。 When you are using a Grid Hub and a separate Grid Node ( see my link here for sample launch instructions: https://gist.github.com/djangofan/5174433 ) then you should be invoking RemoteWebDriver rather than WebDriver, like so (or similar): 当您使用Grid Hub和单独的Grid Node时(请参阅我的链接以获取示例启动说明: https ://gist.github.com/djangofan/5174433),那么您应该像这样调用RemoteWebDriver而不是WebDriver(或类似):

WebDriver driver = new RemoteWebDriver (
     new URL("http://localhost:4444/wd/hub"), 
     DesiredCapabilities.firefox()
);
driver.get("http://www.google.com");

This work for me: Root cause: On IE 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. 这对我有用:根本原因:在Windows Vista或Windows 7的IE 7或更高版本上,必须将每个区域的保护模式设置设为相同的值。 The value can be on or off, as long as it is the same for every zone. 该值可以打开或关闭,只要每个区域都相同即可。 To set the Protected Mode settings, choose "Internet Options..." from the Tools menu, and click on the Security tab. 要设置保护模式设置,请从“工具”菜单中选择“ Internet选项...”,然后单击“安全性”选项卡。 For each zone, there will be a check box at the bottom of the tab labeled "Enable Protected Mode". 对于每个区域,选项卡底部都会有一个标记为“启用保护模式”的复选框。

Hope it works for you. 希望对你有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM