51Testing软件测试论坛

标题: selenium phantomjs java无界面浏览器环境搭建 [打印本页]

作者: lsekfe    时间: 2018-7-4 14:50
标题: selenium phantomjs java无界面浏览器环境搭建
java selenium搭建无界面浏览器
1.http://phantomjs.org/
下载windows版phantomjs
[attach]116961[/attach]
[attach]116962[/attach]
2.解压后bin目录下会有exe文件
[attach]116963[/attach]
3.测试代码:
  1. package se;
  2. import org.openqa.selenium.WebDriver;
  3. import org.openqa.selenium.firefox.FirefoxDriver;
  4. import org.openqa.selenium.phantomjs.PhantomJSDriver;
  5. public class test {

  6.     public static void main(String[] args) {
  7.         // TODO Auto-generated method stub
  8.     //    System.setProperty("webdriver.gecko.driver", "C:\\Program Files (x86)\\Mozilla Firefox\\geckodriver.exe");
  9.         System.setProperty("phantomjs.binary.path", "C:\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
  10.     //    WebDriver driver = new FirefoxDriver();
  11.         WebDriver driver = new PhantomJSDriver();
  12.         driver.get("http://www.baidu.com");
  13.         System.out.println(driver.getCurrentUrl());
  14.         

  15.     }

  16. }
复制代码
4.url成功打印
[attach]116964[/attach]







欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2