2014-01-24 53 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,可信站點,受限站點)對我來說已經足夠了。