回答

1

這裏是它的答案:

String Xport = System.getProperty("lmportal.xvfb.id", ":99"); 
final File firefoxPath = new File(System.getProperty("lmportal.deploy.firefox.path", "/opt/firefox/firefox")); 
FirefoxBinary firefoxBinary = new FirefoxBinary(firefoxPath); 
firefoxBinary.setEnvironmentProperty("DISPLAY", Xport); 

FirefoxDriver driver = new FirefoxDriver(firefoxBinary,null); 

driver.get(url); 

Thread.sleep(1500); 
res.setContentType("text/html;charset=UTF-8"); 
PrintWriter out = res.getWriter(); 
String str = driver.getPageSource(); 
out.println(str); 

out.close(); 
driver.quit(); 

並安裝到您的EC2實例的XVFB和firefox那inportant .....