我已经编写了一个 java 代码来使用 selenium web 驱动程序捕获网页的屏幕截图,通常 java 代码运行良好,但是在 servlet 中使用相同的代码会给我一个错误。
package CaptureImages;
public class SeleniumTest extends HttpServlet{
private static final long serialVersionUID = 1L;
public void service(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException{
WebDriver driver_rbi = new FirefoxDriver();
// WebDriver driver_rbi=new HtmlUnitDriver(); //html unit driver
driver_rbi.get("http://www.rbi.org.in/commonman/English/Scripts/BanksInIndia.aspx");
try{
//CaptureRBI.captureRBIScreens();
System.out.println("webpage launched...");
//File scrFile = ((TakesScreenshot) driver_rbi).getScreenshotAs(OutputType.FILE);
//FileUtils.copyFile(scrFile, new File("C:\\Users\\srawat2\\Desktop\\surya code\\selenium\\ScreenShots\\RBI\\RBI.png"));
System.out.println("Quiting driver...");
//driver_rbi.quit();
}
catch(Exception e){
}
// PrintWriter out = response.getWriter();
}
} 错误:java.lang.ClassNotFoundException:com.google.common.base.Function
最佳答案
你需要谷歌 Guava Library .事实上,解决此问题后,您将需要大量其他库。因此,最好在类路径中包含所有 selenium 库。
关于java - 使用 Tomcat 服务器从 Servlet 启动 Selenium Web 驱动程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28559453/