2014-01-24 48 views
2

下面的代码在Firefox和Chrome中正常工作,但在IE中执行时显示错误。I/O异常和无法找到元素在使用Selenium Webdriver的IE中

System.setProperty("webdriver.ie.driver", "G:\\Selenium\\IEDriver\\IEDriverServer.exe"); 
    WebDriver driver=new InternetExplorerDriver(); 
    driver.get("https://www.google.co.in/?gws_rd=cr&ei=ZDziUrLDEuLpiAeD44H4BA"); 
    driver.findElement(By.name("q")).sendKeys("Selenium"); 

显示的错误是I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: recv failed Jan 24, 2014 3:44:04 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute INFO: Retrying request Exception in thread "main" org.openqa.selenium.NoSuchElementException:

+0

什么版本的IE? IE 11完全不受支持。 – JimEvans

+0

IE的版本是10 – Dinu

回答

8

的问题是与我的IE设置。当IE中的安全设置更改为“Internet”,“本地Intranet”,“可信站点”和“受限站点”的“启用保护模式”时,问题得到解决。您可以通过转到“Internet选项”安全选项卡并启用所有区域的“启用保护模式”复选框来更改它。我能够从链接中获得这些信息http://jimevansmusic.blogspot.in/2012/08/youre-doing-it-wrong-protected-mode-and.html

0

请检查下面的Python代码(应该由类似的Java):

from selenium import webdriver 

def findElement(browser): 
    browser.get("https://www.google.co.in/?gws_rd=cr&ei=ZDziUrLDEuLpiAeD44H4BA") 
    element = browser.find_element_by_name("q") 
    return element.get_attribute("outerHTML") 

ieBrowser = webdriver.Ie() 
print "IE: "+findElement(ieBrowser) 

ffBrowser = webdriver.Firefox(firefox_profile=webdriver.FirefoxProfile()) 
print "FF: "+findElement(ffBrowser) 

上述代码的输出是:

IE: <input id="lst-ib" class="lst lst-tbb" title="חיפוש" name="q" maxLength="2048" value="" size="41" type="text" autocomplete="off"> 

FF: <input spellcheck="false" dir="ltr" style="border: medium none; padding: 0px; margin: 0px; height: auto; width: 100%; background: url(&quot;data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw%3D%3D&quot;) repeat scroll 0% 0% transparent; position: absolute; z-index: 6; left: 0px; outline: medium none;" id="gbqfq" class="gbqfif" name="q" autocomplete="off" value="" type="text"> 

所以我能够在两个浏览器中找到你正在寻找的元素(使用Selenium v​​2.39.00)。

+0

显示同样的错误...! – Dinu

+0

这两个选项都不起作用..显示相同的错误..甚至在谷歌加载完全之前显示错误。 – Dinu

+0

您是否尝试打开IE并手动导航到此URL? –

0

你可以尝试等待能与Explicit wait可见的元素,

new WebDriverWait(driver,60).until(ExpectedConditions.visibilityOfElementLocated(By.id("gbqfq"))).sendKeys("Selenium"); 
+0

现在还出现了错误:findElement引发的WebDriverException(By.id:gbqfq) org.openqa.selenium.NoSuchWindowException:无法在关闭的窗口中查找元素(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:13毫秒 – Dinu

0

在四个选项中配置启用保护模式(Internet,本地Intranet,可信站点,受限站点)对我来说已经足够了。