簡體   English   中英

如何使用 Selenium WebDriver 啟動 InternetExplorerDriver

[英]How can I start InternetExplorerDriver using Selenium 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

它需要在所有區域中設置相同的安全級別。 要做到這一點,請按照以下步驟操作:

1.打開瀏覽器

2.轉到工具-> Internet選項->安全

3.將所有區域(Int​​ernet、本地Intranet、受信任的站點、受限制的站點)設置為相同的保護模式,啟用或禁用應該無關緊要。

最后,通過右鍵單擊位於右上角的齒輪並啟用狀態欄,將縮放級別設置為 100%。 默認縮放級別現在顯示在右下方。

我認為您必須進行一些必需的配置才能正確啟動和運行 IE。 您可以在以下位置找到指南: https : //github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver

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");
  }
    }

在過去的一個月里,我一直在解決這個問題。 最后我找到了一個富有成效的解決方案。 以下是我們為使其工作而遵循的確切步驟。 我已經完成了此鏈接中提到的必需配置https : //github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration

  1. 為所有區域啟用/禁用Internet Explorer保護模式設置 (在我的情況下,我啟用了所有區域,與級別無關)。 如果您的組織不允許這些設置,另一種解決方案是在 Active Directory 級別創建一個組並為該組強制執行我們預期的 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 中提到的 selenium 版本

    <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.exe) (不要以管理員身份打開regedit )並在 regedit 中為以下路徑添加TabProcGrowth

HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\Main

右鍵單擊 Main 並添加新的 DWORD(32 位)並將其設為 0。請記住,我使用 QWORD 嘗試了 64 位,但它對我不起作用。

這個過程的關鍵是第2步,即為windows安裝IE Webdriver工具

我沒有為 Selenium 最新版本 3.0 嘗試過這種方法,但會嘗試一下。

與 Chrome 瀏覽器一樣,下面是需要考慮的事情。

步驟 1--> 導入 Chrome 所需的文件:
import org.openqa.selenium.chrome.*;

步驟 2--> 設置路徑並初始化 Chrome 驅動程序:

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

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

步驟 3--> 創建 Chrome 瀏覽器實例

WebDriver driver = new ChromeDriver();

休息將與...

首先下載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");
    }
}

下面的代碼片段肯定會起作用:

    InternetExplorerOptions ops = new InternetExplorerOptions();
    // ops.ignoreZoomSettings(); -- Not necessarily in case 100% zoom.
    ops.introduceFlakinessByIgnoringSecurityDomains(); -- Necessary to skip protected 
     mode setup

    System.setProperty("webdriver.ie.driver",
            <path>\\IEDriverServer.exe");
    WebDriver dr = new InternetExplorerDriver(ops);

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

var options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
options.ElementScrollBehavior = InternetExplorerElementScrollBehavior.Bottom;
  1. 您必須將每個區域的保護模式設置設為相同的值。
  2. 所有區域的增強保護模式必須相同。 (我更喜歡禁用它,因為這是 IE 10 及更高版本的要求。)

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

以上步驟怎么做???

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

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

希望這會有所幫助。 謝謝:)

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);

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%

以下步驟對我有用,希望這對你也有用,

  1. 打開 Internet Explorer。
  2. 導航到工具->選項
  3. 導航到安全選項卡
  4. 單擊“將所有區域重置為默認級別”按鈕
  5. 現在,對於 Internet、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);

要在 IE 瀏覽器中運行測試用例,請確保您已下載 IE 驅動程序,並且還需要設置該屬性。

下面的代碼會幫助你

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

// Initialise browser

WebDriver driver=new InternetExplorerDriver();

您可以使用 Selenium完整代碼檢查IE 瀏覽器挑戰以獲取更多詳細信息

為所有區域啟用保護模式 您需要從 Internet 選項 -> 安全選項卡為所有區域啟用保護模式。 為所有區域啟用保護模式。

http://codebit.in/question/1/selenium-webdriver-java-code-launch-internet-explorer-brow

包瀏覽器;

導入 org.openqa.selenium.WebDriver; 導入 org.openqa.selenium.ie.InternetExplorerDriver;

公共課你好{

public static void main(String[] args) {


    // setting IEdriver property
    System.setProperty("webdriver.ie.driver",
            "paste the path of the IEDriverserver.exe");

    WebDriver driver = new InternetExplorerDriver();

    // launching the google home screen
    driver.get("https://www.google.com/?gws_rd=ssl");

}

} //希望這會奏效

這里已經有了一些不錯的答案。 我只是想向您展示一種更高級的方式,如何輕松地忘記設置瀏覽器來運行測試的困難。

在你的execute方法中,你只需要使用免費的TestProject SDK中的幫助器,如下例所示:

import io.testproject.java.sdk.v2.drivers.WebDriver;

import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
import io.testproject.java.sdk.v2.tests.WebTest;
import io.testproject.java.sdk.v2.tests.helpers.WebTestHelper;

  public class Example implements WebTest {
     @Override
  public ExecutionResult execute(WebTestHelper helper) throws FailureException {

    WebDriver driver = helper.getDriver();

    driver.testproject().navigateToUrl("https://www.google.com");

    return ExecutionResult.PASSED;
  }
}

並在@Before方法中設置Runner瀏覽器類型

@Before
public void setup() throws InstantiationException {
    runner = Runner.createWeb("devtoken", AutomatedBrowserType.Chrome);
}

轉到工具 -> Internet 選項 -> 安全並為所有區域啟用保護模式。 它對我有用:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM