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

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



你可能感兴趣的:(driver,selenium;chrome,driver;ie)