在本节中, 你将学习如何在IE浏览器上运行Selenium测试脚本。
Internet Explorer使用Internet Explorer驱动程序服务器实现WebDriver协议。 Internet Explorer驱动程序服务器是Selenium中的测试与Internet Explorer浏览器之间的链接。
让我们考虑一个测试案例, 我们将尝试在IE浏览器中自动执行以下方案。
- 启动IE浏览器。
- 公开网址:www.google.com
- 最大化浏览器。
- 输入值” srcmini tutorials”
- 点击搜索按钮。
我们将在同一测试套件(Demo_Test)中创建第四个测试用例。
步骤1。右键单击” src”文件夹, 然后从”新建”>”类”创建一个新的类文件。输入你的班级名称为”第四”, 然后单击”完成”按钮。


第2步。在浏览器中打开网址:http://selenium-release.storage.googleapis.com/index.html?path=2.48/。
第三步选择最新版本并根据你当前正在使用的操作系统下载。
对于Windows 64位, 单击” IEDriverServer x64 2.48.0 zip”下载。

下载的文件将是压缩格式。将内容解压缩到方便的目录中。

步骤4。将系统属性” webdriver.ie.driver”设置为IEDriverServer.exe文件的路径, 并实例化IEDriver类。
这是执行此操作的示例代码。
// System Property for IEDriver
System.setProperty("webdriver.ie.driver", "D:\\IE Driver Server\\IEDriverServer.exe");
// Instantiate a IEDriver class.
WebDriver driver=new InternetExplorerDriver();
第五步现在该进行编码了。我们为每个代码块都嵌入了注释, 以清楚地说明这些步骤。
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Fourth {
public static void main(String[] args) {
// System Property for IEDriver
System.setProperty("webdriver.ie.driver", "D:\\IE Driver Server\\IEDriverServer.exe");
// Instantiate a IEDriver class.
WebDriver driver=new InternetExplorerDriver();
// Launch Website
driver.navigate().to("http://www.google.com/");
//Maximize the browser
driver.manage().window().maximize();
// Click on the search text box and send value
driver.findElement(By.id("lst-ib")).sendKeys("srcmini tutorials");
// Click on the search button
driver.findElement(By.name("btnK")).click();
}
}
Eclipse代码窗口将如下所示:

第六步右键单击Eclipse代码, 然后选择运行方式> Java应用程序。

第六步以上测试脚本的输出将显示在Internet Explorer浏览器中。
