http://www.seleniumhq.org/ selenium启动各浏览器程序
下载最新程序
启动IE浏览器:
import org.openqa.selenium.*;
importorg.openqa.selenium.ie.InternetExplorerDriver;
System.setProperty("webdriver.ie.driver","C:\\testdriver\\IEDriverServer.exe");
DesiredCapabilities ieCapabilities =DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
WebDriver IEWebDriver = newInternetExplorerDriver(ieCapabilities);
IEWebDriver.get("http://www.baidu.com");
启动firefox浏览器:
importorg.openqa.selenium.firefox.FirefoxDriver;
importorg.openqa.selenium.firefox.FirefoxProfile;
FirefoxProfile profile = newFirefoxProfile();
profile.setPreference("general.useragent.override","Mozilla/5.0(iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML,like Gecko) Version/4.0 Mobile/7A341 Safari/528.16");
System.setProperty("webdriver.firefox.bin","C:\\ProgramFiles (x86)\\Mozilla Firefox\\firefox.exe");
WebDriver mdriver = newFirefoxDriver(profile);
启动google浏览器:
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.chrome.ChromeDriver;
System.setProperty("webdriver.chrome.driver","C:\\testdriver\\chromedriver.exe");
WebDriver driver = newChromeDriver();
启动HtmlUnitDriver.(html unitDriver 内存运行是不支持截图功能的哦)
importorg.openqa.selenium.htmlunit.HtmlUnitDriver;
driver = new HtmlUnitDriver();
本文出自 “软件测试” 博客,谢绝转载!
Selenium +java+webdriver 启动各浏览器
原文:http://chineseliubo.blog.51cto.com/3683952/1620163