如何使用Selenium WebDriver启动InternetExplorerDriver

我下载了驱动程序,并在代码中给出了确切的路径,但是当我运行代码时,它显示错误

我的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.打开IE浏览器

2.转到工具 – > Internet选项 – >安全性

3.将所有区域(Int​​ernet,本地Intranet,受信任站点,受限制站点)设置为相同的受保护模式,启用或禁用无关紧要。

最后,通过右键单击位于右上角的齿轮并启用状态栏,将“缩放”级别设置为100%。 默认缩放级别现在显示在右下方。

我认为你必须做一些必要的配置来正确启动和运行IE。 您可以在以下url找到该指南: 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的保护模式设置 。 (就我而言,我启用了所有区域,与级别无关)。 如果您的组织不允许这些设置,则另一种解决方案是在活动目录级别创建一个组,并为该组强制执行我们预期的Internet Explorer设置。 将您的用户名添加到该组。
  2. 从以下链接安装Windows的IE Webdriver工具 。 这是来自微软。 安装后无需重启机器https://www.microsoft.com/en-au/download/details.aspx?id=44069
  3. 将这些所需function用于您的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. 使用适当的selenium版本2.53.1 。 我把它用于pom中提到的selenium版本

      org.seleniumhq.selenium selenium-java 2.53.1  
  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(); 

rest将与……相同

首先下载IEDriverServer的exe文件(64位和32位)。 不需要安装,只需用浏览器下载此文件(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"); } } 

在c#中,这可以绕过更改保护区域设置。

 var options = new InternetExplorerOptions(); options.IntroduceInstabilityByIgnoringProtectedModeSettings = true; options.ElementScrollBehavior = InternetExplorerElementScrollBehavior.Bottom; 
  1. 您必须为每个区域设置保护模式设置为相同的值。
  2. 所有区域的增强保护模式必须相同。 (我更喜欢它被禁用,因为这是IE 10及更高版本的要求。)

此外,必须为IE 10及更高版本禁用“增强保护模式”。 此选项位于“Internet选项”对话框的“高级”选项卡中。

如何做以上步骤???

看看这个video: 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选项 – >安全性并启用所有区域的保护模式。 它对我有用:)