Java 如何使用 Selenium WebDriver 启动 InternetExplorerDriver
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20115474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I start InternetExplorerDriver using Selenium WebDriver
提问by Sakib Espak
I downloaded the driver and I gave the exact path in my code but when I ran the code it shows me error
我下载了驱动程序,并在我的代码中给出了确切的路径,但是当我运行代码时,它显示了我的错误
my code with java is as below:
我的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/");
and the error message is
错误信息是
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
回答by Abhishek Singh
It needs to set same Security level in all zones. To do that follow the steps below:
它需要在所有区域中设置相同的安全级别。要做到这一点,请按照以下步骤操作:
1.Open IE
1.打开浏览器
2.Go to Tools -> Internet Options -> Security
2.转到工具-> Internet选项->安全
3.Set all zones (Internet, Local intranet, Trusted sites, Restricted sites) to the same protected mode, enabled or disabled should not matter.
3.将所有区域(Internet、本地Intranet、受信任的站点、受限制的站点)设置为相同的保护模式,启用或禁用应该无关紧要。
Finally, set Zoom level to 100% by right clicking on the gear located at the top right corner and enabling the status-bar. Default zoom level is now displayed at the lower right.
最后,通过右键单击位于右上角的齿轮并启用状态栏,将缩放级别设置为 100%。默认缩放级别现在显示在右下方。
回答by Rupesh Shinde
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");
}
}
回答by Rupesh Shinde
In the same way for Chrome Browser below are the things to be considered.
与 Chrome 浏览器一样,下面是需要考虑的事情。
Step 1-->Import files Required for Chrome :import org.openqa.selenium.chrome.*;
步骤 1--> 导入 Chrome 所需的文件:import org.openqa.selenium.chrome.*;
Step 2--> Set the Path and initialize the Chrome Driver:
步骤 2--> 设置路径并初始化 Chrome 驱动程序:
System.setProperty("webdriver.chrome.driver","S:\chromedriver_win32\chromedriver.exe");
Note:In Step 2 the location should point the chromedriver.exe file's storage location in your system drive
注意:在第 2 步中,位置应指向 chromedriver.exe 文件在系统驱动器中的存储位置
step 3--> Create an instance of Chrome browser
步骤 3--> 创建 Chrome 浏览器实例
WebDriver driver = new ChromeDriver();
Rest will be the same as...
休息将与...
回答by Angel1403
Go to Tools -> Internet Options -> Security and Enable protection mode for all zones. It worked for me :)
转到工具 -> Internet 选项 -> 安全并为所有区域启用保护模式。它对我有用:)
回答by mkkhedawat
In c#, This can bypass changing protected zone settings.
在 c# 中,这可以绕过更改保护区设置。
var options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
options.ElementScrollBehavior = InternetExplorerElementScrollBehavior.Bottom;
回答by ER.swatantra
First download the exe file of the IEDriverServer (64 bit and 32 bit). Don't need to install, only download this file with your browser( 64 or 32 bit) and simply give the path of the exe file in the given code.
首先下载IEDriverServer(64位和32位)的exe文件。不需要安装,只需使用您的浏览器(64 位或 32 位)下载此文件,并在给定代码中提供 exe 文件的路径。
http://www.seleniumhq.org/download/
http://www.seleniumhq.org/download/
use this code
使用此代码
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");
}
}
回答by Rameshwar
- You must set Protected Mode settings for each zone to be the same value.
- Enhanced Protected Mode for all zones must be same. (I prefer it to be disabled as this is the requirement for IE 10 and higher.)
- 您必须将每个区域的保护模式设置设为相同的值。
- 所有区域的增强保护模式必须相同。(我更喜欢禁用它,因为这是 IE 10 及更高版本的要求。)
Additionally, "Enhanced Protected Mode" must be disabled for IE 10 and higher. This option is found in the Advanced tab of the Internet Options dialog.
此外,必须为 IE 10 及更高版本禁用“增强保护模式”。此选项位于 Internet 选项对话框的高级选项卡中。
How to do above steps???
以上步骤怎么做???
Have look at this video: http://screencast.com/t/5nlxsrje4I. I have showed the steps.
看看这个视频:http: //screencast.com/t/5nlxsrje4I。我已经展示了步骤。
Source: https://code.google.com/p/selenium/wiki/InternetExplorerDriver#Required_Configuration
来源:https: //code.google.com/p/selenium/wiki/InternetExplorerDriver#Required_Configuration
Hope this helps. Thank you :)
希望这可以帮助。谢谢 :)
回答by taynguyen
I think you have to make some required configuration to start and run IE properly. You can find the guide at: https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver
我认为您必须进行一些必需的配置才能正确启动和运行 IE。您可以在以下位置找到指南:https: //github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver
回答by Krushna Chulet
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);
回答by Pushpak Jain
1---Enable protected mode for all zones You need to enable protected mode for all zones from Internet Options -> Security tab. To enable protected mode for all zones
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
This setting will resolve error related to "Protected Mode settings are not the same for all zones.
此设置将解决与“所有区域的保护模式设置不同”相关的错误。
2-- Set IE browser's zoom level 100%
2-- 设置IE浏览器的缩放级别100%
Open Internet Explorer browser.
Go to menu View -> Zoom -> Select 100%