-1

I have a Selenium Script which as below :

package TestCase;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class TestCase {

    public static void main(String[] args)
    {
        System.setProperty("webdriver.firefox.marionette","/root/Desktop/Selenium/GeckoDriver/geckodriver.exe");
        for(int i=0;i<5;i++)
        {
            WebDriver driver = new FirefoxDriver();
            driver.get ("http://cl.amtrustmobilesolutions.asia/cs/login.php");
            WebElement username=driver.findElement(By.name("user_name"));
            username.sendKeys("username");
            WebElement passsword=driver.findElement(By.name("user_password"));
            passsword.sendKeys("password");
            driver.findElement(By.xpath("//button[contains(@class,'buttonuser')]")).click();

        }
    }
}

I want to trigger this script using a JSP page :

<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

         pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  <title>Enter your name</title>
</head>
<body>

<jsp:useBean id = "TestBean" class = "TestCase.TestCase" />

</body>
</html>

But it gave me an error :

Internal Server Error

The server encountered an internal error that prevented it from fulfilling this request.

java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1 logs.

How can I use JSP pages to trigger the Selenium Script?

James Z
  • 12,209
  • 10
  • 24
  • 44
Nirbhay Shah
  • 197
  • 1
  • 7
  • 1
    Why do you want it to specifically start the script through JSP?. I dont think the idea is feasible. Unless you have a server that can launch a virtual machine or a docker container and get the result from that. Still this can only launch the service in the background. Not the static class that you have written – karthick Jan 09 '18 at 06:28
  • My Aim is to trigger the selenium script using a custom built front end through which I can pass certain variables like username password etc @karthick, can you suggest any other way to achieve this result – Nirbhay Shah Jan 09 '18 at 06:30

2 Answers2

0

NoClassDefFoundError means that Webdriver is not found in the class path. Please add it to the dependencies.

Also check the thread - How to call Java class in Jsp

ArunPrakash
  • 138
  • 1
  • 7
0

What you are looking for is Scriptlet. Write your selenium code in a scriptlet and trigger the scriptlet after you have entered your values. You can also use the entered values in your scriptlet.

This might get you started.

https://www.javatpoint.com/jsp-scriptlet-tag

hiren
  • 1,067
  • 1
  • 9
  • 16