【问题标题】:I/O Exception and Unable to find element In IE using Selenium WebdriverI/O 异常和无法在 IE 中使用 Selenium Webdriver 找到元素
【发布时间】:2014-02-15 07:03:31
【问题描述】:

以下代码在 Firefox 和 chrome 上运行良好,但在 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:

【问题讨论】:

  • 什么版本的IE? IE 11 还完全不受支持。
  • IE版本为10

标签: java eclipse internet-explorer selenium


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    您可以尝试使用Explicit wait 等待元素可见,

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

    【讨论】:

    • 现在也发生错误:由 findElement(By.id: gbqfq) org.openqa.selenium.NoSuchWindowException 引发的 WebDriverException:无法在关闭的窗口上找到元素(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:13毫秒
    【解决方案3】:

    请查看以下 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)。

    【讨论】:

    • 两个选项都不起作用.. 显示相同的错误.. 甚至在谷歌完全加载之前显示错误。
    • 好的;答案修改。您可能想检查您的 Selenium 版本以及 IEDriverServer.exe 文件的版本。
    • 您可以在每个浏览器上手动查看该网页的源代码。在FF中应该可以找到name=q,在IE中应该可以找到name="q"
    【解决方案4】:

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

    【讨论】:

      猜你喜欢
      • 2016-09-07
      • 1970-01-01
      • 1970-01-01
      • 2021-01-02
      • 2015-05-04
      • 1970-01-01
      • 2014-05-29
      • 2016-08-31
      • 2023-04-01
      相关资源
      最近更新 更多