selenium chrome driver 和IE driver 常见问题(2)

本文档展示了在使用Selenium自动化测试时,如何配置Chrome和Internet Explorer的驱动程序。针对IE,特别强调了需要设置'webdriver.ie.driver'系统属性,并提供了错误处理的示例,同时提醒用户从Selenium官方网站下载最新的IEDriverServer.exe并将其路径添加到系统路径中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

package com.selenium.test;
 import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
 public class TempGoogle {
        public static void main(String[] args) {
                final String sUrl = "http://www.google.com.hk/";            System.setProperty("webdriver.ie.driver","C:\\Users\\yren9\\workspace\\selenium\\IEDriverServer.exe");
            DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
            ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
            WebDriver oWebDriver = new InternetExplorerDriver(ieCapabilities);
            oWebDriver.get(sUrl);
            try {                        Thread.sleep(1000);
                } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
         // Use name locator to identify the search input field.
            WebElement oSearchInputElem = oWebDriver.findElement(By.name("q")); 
            oSearchInputElem.sendKeys("smilejay");
            WebElement oGoogleSearchBtn = oWebDriver.findElement(By.xpath("//input[@name='btnK']"));  
            oGoogleSearchBtn.click();
 try {                Thread.sleep(5000);
            }
            catch(InterruptedException ex) {                System.out.println(ex.getMessage());
            }
 oWebDriver.close();
        }
}

1. 需要设置IE的Driver到“webdriver.ie.driver”变量中,否则可能遇到报错信息:
The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see http://code.google.com/p/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://code.google.com/p/selenium/downloads/list
2012-9-2 16:09:02 org.openqa.selenium.ie.InternetExplorerDriverServer initializeLib
警告: This method of starting the IE driver is deprecated and will be removed in selenium 2.26. Please download the IEDriverServer.exe from http://code.google.com/p/selenium/downloads/list and ensure that it is in your PATH.
更具提示,需要添加IEDriverServer.exe(从Selenium官网可下载的),并用如下的代码进行设置。
System.setProperty(“webdriver.ie.driver”,”C:\\Users\\yren9\\workspace\\selenium\\IEDriverServer.exe
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值