简体   繁体   中英

Selenium and java servlet and javaScript

I have a situation in which I want Selenium webdriver to run on client.

I have a webpage with Submit button inside form.

In form's action attribute I am calling servlet action="servletName" .

Now in servlet I have following

@WebServlet("/servletName")
public class chckserv extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException 
{
 System.setProperty("webdriver.gecko.driver","path//geckodriver.exe");
 System.out.println("In Servlet");
 WebDriver driver = new FirefoxDriver();
 driver.get("https://www.google.com");
 response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
 response.getOutputStream().write("Done".getBytes("UTF-8"));
 response.getOutputStream().flush();
 response.getOutputStream().close(); 
 }
}

When I click on button on HTML page WebDriver instance is getting started on server.

Now here is waht I want to do. The webdriver instance should be running at client side.

Is it possible in any way keeping in mind current scenario??

The webdriver instance should be running at client side.

Am guessing that you are referring to a remote machine which is not the same one as the machine on which your servlet is running.

If that's a correct guess, then yes you can very well do this. You would need to make use of the Selenium Grid for doing this.

You would make use of

RemoteWebDriver driver = new RemoteWebDriver(new URL("http://remoteHostIP:remoteHostPort/wd/hub"), DesiredCapabilities.firefox());

to instantiate your webdriver instance.

Take a look at the below documentation to learn how to work with the Selenium Grid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM