selenium-浏览器的启动

上一篇 / 下一篇  2016-07-13 21:47:53 / 个人分类:Selenium

上一篇中说了selenium元素定位,那么这篇讲下怎样启动浏览器
1、firefox浏览器
 1) 如果是默认安装在C盘,可直接通过下面的方式启动
  WebDriver driver=new FirefoxDriver();
 2) 如果不是默认安装,则需要将firefox.exe配置到系统变量中去

    System.setProperty("webdriver.firefox.bin","C:\\Program Files (x86)\Mozilla Firefox\\firefox.exe");

     WebDriver driver = new FirexDriver();
   3)如果用户设置了firefox的profile,例如打开HTTPS这样的网址,如直接用new FirefoxDriver()的话打开后需要将此网址添加后才能打开。
  File profileDir = new File("C:\\Users\\test\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\2ziq4yrx.default");
FirefoxProfile profile = new FirefoxProfile(profileDir);
profile.setEnableNativeEvents(true);
   怎样设置firefox的profile呢?,在运行窗口中输入firefox.exe -ProfileManager,点击确定。点击[创建配置文件],创建一个新的profile
     4)打开浏览器设置浏览器的语言
                FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("intl.accept_languages", “zh-CN”);
2、IE浏览器.ie是由driverServer来驱动,所以下载相应的驱动
     System.setProperty("webdriver.ie.driver","C:\\Automation\\IEDriverServer.exe");
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer(); 
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver = new InternetExplorerDriver(ieCapabilities);
3、启动chrome浏览器
       System.setProperty("webdriver.ie.driver", "C:\\Automation\\chromedriver.exe");
       WebDriver driver = new ChromeDriver();

IE和chrome的驱动最好放在项目的路径下,启动地址就填写相对地址


TAG: 浏览器

 

评分:0

我来说两句

我的栏目

日历

« 2024-04-22  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 3603
  • 日志数: 3
  • 建立时间: 2013-04-09
  • 更新时间: 2016-07-13

RSS订阅

Open Toolbar