2013-11-21 59 views
5

我下載的驅動程序,我給我的代碼的確切路徑,但是,當我跑它顯示的代碼我錯誤如何開始InternetExplorerDriver使用硒的webdriver

我用java代碼如下:

System.out.println("Internet Explorer is selected"); 
System.setProperty("webdriver.ie.driver","C:\\Program Files\\Selenium\\Drivers\\IEDriver\\IEDriverServer.exe"); 
driver = new InternetExplorerDriver(); 
selenium = new WebDriverBackedSelenium(driver, "http://www.datamoat.com/"); 

和錯誤消息是

org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 1.15 seconds 
Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:15:02' 
System info: host: 'SAKIB-PC', ip: '192.168.10.70', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_25' 
Driver info: org.openqa.selenium.ie.InternetExplorerDriver 
+3

閱讀錯誤消息。它說什麼? – Arran

+0

錯誤的主要部分是「保護模式設置對於所有區域都不相同」。因此,爲所有區域設置相同的保護模式。 –

回答

8

需要設置相同的安全級別在所有區域。要做到這一點請遵循以下步驟:

1.Open IE

2.進入工具 - > Internet選項 - >安全

3.設置所有區域(Int​​ernet,本地Intranet,受信任的網站,受限站點)到相同的受保護模式,啓用或禁用應該沒有關係。

最後,右鍵點擊位於右上角的齒輪並啓用狀態欄,將縮放級別設置爲100%。默認縮放級別現在顯示在右下角。

+0

感謝您的信息。現在你可以告訴我,我怎麼能爲鉻驅動程序做同樣的事情? –

+0

@Sakib:錯誤是特定於Internet Explorer,所以你想如何「爲鉻驅動程序相同的事情」? – chiccodoro

+0

Chrome並不需要做同樣的事情。這隻需要完成IE –

2
import org.openqa.selenium.WebDriver; 

import org.openqa.selenium.ie.*; 

public class IEclass { 



public static void main(String[] args) { 

System.setProperty("webdriver.ie.driver","S:\\IE and Chrome ServerDriver\\IEDriverServer.exe"); 

WebDriver driver = new InternetExplorerDriver(); 

driver.get("https://www.google.com"); 
    } 
    } 
+1

請格式化您的代碼,並嘗試給出一個簡短的解釋,讓您的答案更有用! – leo

+0

肯定的利奧......這是我的第一篇文章。 –

1

與以下Chrome瀏覽器相同的方式是要考慮的事情。

第1步 - 您需要爲Chrome瀏覽器>導入文件:
import org.openqa.selenium.chrome.*;

第2步 - >設置路徑和初始化鉻司機:

System.setProperty("webdriver.chrome.driver","S:\\chromedriver_win32\\chromedriver.exe"); 

注意:在步驟2中,該位置應將chromedriver.exe文件的存儲位置指向您的系統驅動器

第3步 - >創建Chrome瀏覽器的一個實例

WebDriver driver = new ChromeDriver(); 

其餘部分將是相同的......

-1

進入工具 - > Internet選項 - >安全和啓用保護模式所有區域。它爲我工作:)

0

在c#中,這可以繞過更改保護區設置。

var options = new InternetExplorerOptions(); 
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true; 
options.ElementScrollBehavior = InternetExplorerElementScrollBehavior.Bottom; 
1

首先下載IEDriverServer(64位和32位)的exe文件。 不需要安裝,只需使用您的瀏覽器(64或32位) 下載此文件,並在給定的代碼中給出exe文件的路徑。

http://www.seleniumhq.org/download/

使用此代碼

package myProject; 

import org.openqa.selenium.ie.InternetExplorerDriver; 

public class Browserlaunch { 

    public static void main(String[] args) { 

     System.setProperty("webdriver.ie.driver", "C:/Drivers/IEDriverServer.exe"); 
     InternetExplorerDriver IEDriver=new InternetExplorerDriver(); 
     IEDriver.get("http://localhost:8888"); 
    } 
} 
0
  1. 你必須爲每個區域設置保護模式設置爲相同的值。
  2. 所有防區的增強保護模式必須相同。 (我更喜歡它被禁用,因爲這是IE 10及更高版本的要求。)

此外,對於IE 10和更高版本,必須禁用「增強保護模式」。該選項位於「Internet選項」對話框的「高級」選項卡中。

如何做到上述步驟???

看看這個視頻:http://screencast.com/t/5nlxsrje4I。我已經展示了這些步驟。

來源:https://code.google.com/p/selenium/wiki/InternetExplorerDriver#Required_Configuration

希望這有助於。謝謝:)

0
static WebDriver driver; 
System.setProperty("webdriver.ie.driver","C:\\(Path)\\IEDriverServer.exe"); 
driver = new InternetExplorerDriver(); 
driver.manage().window().maximize(); 
driver.get("EnterURLHere");   
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); 
0

1 ---爲 您需要啓用保護模式從Internet選項所有區域的所有區域啓用保護模式 - >安全選項卡。要啓用保護模式爲所有區域

Open Internet Explorer browser. 
Go to menu Tools -> Internet Options. 
Click on Security tab. 
Select Internet from "Select a zone to view or change security settings" and Select(check) check box "Enable Protected Mode" from In the "Security level for this zone" block . 
Apply same thing for all other 3 zones -> Local Internet, Trusted Sites and Restricted Sites 

此設置會解決相關的錯誤,以「保護模式設置不是所有區域相同。

2--設置IE瀏覽器的縮放級別100%

Open Internet Explorer browser. 
Go to menu View -> Zoom -> Select 100% 
0

下面的步驟我都工作過,希望這會爲你工作,以及,

  1. 開放的互聯網EXPLO匯率。
  2. 導航工具 - >選項
  3. 導航到安全選項卡
  4. 點擊「所有區域重置爲默認級別」按鈕,現在
  5. 像互聯網,Intranet,受信任的站點和受限制的站點啓用所有選項「啓用受保護「模式複選框。
  6. 設置IE瀏覽器縮放級別設置爲100%
  7. 然後下面寫代碼的Java文件並運行

    System.setProperty("webdriver.ie.driver","path of your IE driver exe\IEDriverServer.exe"); 
    InternetExplorerDriver driver=new InternetExplorerDriver(); 
    driver.manage().window().maximize(); 
    Thread.Sleep(10100); 
    driver.get("http://www.Google.com"); 
    Thread.Sleep(10000); 
    
0

在IE瀏覽器中運行測試用例,請確保你已經下載IE的驅動程序和你還需要設置屬性。

下面的代碼將幫助您

// This will set the driver 
System.setProperty("webdriver.ie.driver","driver path\\IEDriverServer.exe"); 

// Initialise browser 

WebDriver driver=new InternetExplorerDriver(); 

您可以檢查IE Browser challenges with Seleniumcomplete code更多細節

0

我一直在救火這個問題在過去的一個月。最後我找到了一個富有成效的解決方案。以下是我們遵循的確切步驟。我已經做了必需的配置在這個環節提到:https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration

  1. 使Internet Explorer的保護模式設置啓用/所有區域禁止。 (在我的情況下,我啓用了所有區域,關於關卡並不重要)。如果您的組織不允許這些設置,則另一種解決方案是在活動目錄級別創建一個組,併爲該組實施我們預期的Internet Explorer設置。將您的用戶名添加到該組。
  2. 從以下鏈接安裝用於windows的IE Webdriver工具。這是來自微軟。無需在安裝後重新啓動計算機 https://www.microsoft.com/en-au/download/details.aspx?id=44069
  3. 使用這些期望的能力爲您的Internet Explorer的驅動程序

    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); 
    capabilities.setCapability("requireWindowFocus", true); 
    capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, false); 
    capabilities.setCapability("ie.ensureCleanSession", true); 
    

    capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); capabilities.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true); webDriver = new InternetExplorerDriver(capabilities);

  4. 使用合適的硒版本2.53.1。我得到了它的工作對硒的版本爲POM提到

    <dependency> 
        <groupId>org.seleniumhq.selenium</groupId> 
        <artifactId>selenium-java</artifactId> 
        <version>2.53.1</version> 
    </dependency> 
    
  5. 從下面的鏈接下載IEDriverServer_x64_2.53.1.zip。確保其2.53.1 http://selenium-release.storage.googleapis.com/index.html?path=2.53/

  6. 現在到註冊表中的當前用戶(不要打開regedit作爲管理員)設置(regedit.exe)並在註冊表編輯器中添加TabProcGrowth爲以下路徑

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main

右鍵單擊主,並添加新的DWORD(32位),並使其爲0。還記得我試過64位與QWOR D它沒有爲我工作。

在這個過程中,關鍵是步驟2這是安裝Windows

我沒試過硒最新的3.0版本,這種方法反而會給一個嘗試IE的webdriver工具。