Selenium +java+webdriver 启动各浏览器

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

 

本文出自 “软件测试” 博客,谢绝转载!

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。