Java servlet, Selenium, and JavaScript are a powerful combination of tools that can

I am facing a situation where I need Selenium webdriver to be executed on the client side.

On a webpage, I have a form with a Submit button inside it.

The action attribute of the form calls a servlet named "servletName".

Inside the servlet, the following code is present:

@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(); 
 }
}

Upon clicking the button on the HTML page, the WebDriver instance starts running on the server.

Now, my goal is to have the webdriver instance run on the client side instead.

Is there any possible way to achieve this while considering the current setup?

Answer №1

It is essential for the webdriver instance to be active on the client side.

I assume you are referring to a remote machine different from the one where your servlet is running.

If my assumption is correct, then it is indeed possible. To achieve this, Selenium Grid can be utilized.

You will need to use the following code:

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

This code will help in initializing your webdriver instance.

Refer to the documentation below to understand how Selenium Grid works:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering a NoSuchElementException while trying to select an existing element in Selenium Python

Discovering a solution in the drop-down menu My attempted solution: driver.find_element_by_xpath('/html/body/div[1]/div[1]/div[1]/div/div/div/section[2]/div/div[1]/div/div[2]/div/div/div/div[1]').click() selenium.common.exceptions.NoSuc ...

Utilizing jQuery to update dropdown selection based on JSON object values

In my JSON value, I have the following roles: var roles = { "roles":[ {"role_id":2,"role_name":"admin"}, {"role_id":4,"role_name":"QA"}, {"role_id":3,"role_name":"TL"}, {"role_id":5,"role_name":"user"}, {"role_id":1,"role_name":"r ...

What steps should I take if the slackbot is properly functioning after being invited to the channel?

Using an OAuth2 token I am looking to automate the process of sending data from Google Sheets via Slackbot. Even though I have set up tokens and connections, I find that I still need to manually input the channel id into my script. In order to streamline ...

Is it possible to instantiate a Backbone view by referencing its string name that is stored within a JavaScript object?

I am currently working on a visual builder that utilizes different views for each component. Each view is defined as shown below: $(function() { var parallaxView = new Backbone.view.extend({ .... }); var parallaxView = new Backbone.view.e ...

The issue of duplicate results appearing in the Wikipedia viewer persists even after conducting a second search

I have been working on a project to create a wiki viewer, but I've encountered an issue. Currently, I am utilizing the Wikipedia API. When a user enters a search query, they are presented with 5 possible articles (title and first sentence), and upon ...

Is it possible to display a combination of images and text data using JQUERY/AJAX, when the data is sent as objects or arrays?

I'm struggling to figure out how to handle an object or array sent from a server that contains binary picture and text data using JQUERY/AJAX Here is the server-side setup: const url= require('url'), express = require('express&ap ...

I'm puzzled as to why a div tag suddenly becomes invisible when I attempt to link it with a v-for directive in my code

I am facing an issue with the div tag assigned to the log class. My objective is to populate the text using data retrieved from the API response. However, when I attempt to include the v-for directive, the entire div mysteriously disappears from the brow ...

The problem with the CSS Grid effect

Looking for assistance in creating a grid layout similar to the one on this website: Upon inspecting the page source, I found the following code snippet: http://jsfiddle.net/o45LLsxd/ <div ng-view="" class="ng-scope"><div class="biogrid ng-scope ...

Show the subscription response data in Angular

When utilizing the code snippets below from two different components, I am able to receive a valid response value from the subscriber. dataService.ts fetchFormData(){ return this.http.get('http://localhost:48116/RecuruitmentService.asmx/addRoleTest ...

Extracting a precise data point stored in Mongo database

I have been struggling to extract a specific value from my MongoDB database in node.js. I have tried using both find() and findOne(), but I keep receiving an object-like output in the console. Here is the code snippet: const mongoose = require('mongoo ...

Using various conditions and operators to display or conceal HTML elements in React applications, particularly in NextJS

I am seeking ways to implement conditional logic in my React/Next.js web app to display different HTML elements. While I have managed to make it work with individual variable conditions, I am encountering difficulties when trying to show the same HTML if m ...

How can I determine the package version that is being used when requiring it in Node.js?

I am currently working on resolving an issue with a node module that does not have a package.json. The module contains references to cheerio and superagent: var log = console.log.bind(console), superagent = require('superagent'), cheerio ...

Transforming a React Class Component into a React Functional Component

After struggling for a day with multiple failed attempts, I have been unsuccessful in converting a React Class Component. The original class component code is as follows: class NeonCursor extends React.Component { constructor(props) { super(props); ...

Why do we recreate API responses using JEST?

I've been diving into JavaScript testing and have come across some confusion when it comes to mocking API calls. Most tutorials I've seen demonstrate mocking API calls for unit or integration testing, like this one: https://jestjs.io/docs/en/tuto ...

Getting data from a response in Express.js involves using the built-in methods provided by

I am a beginner at Node.js and I'm currently experimenting with client-server communication. Below are the codes I've been working on: server: app.post('/zsa', (req, res) => { res.send("zsamo"); }); client: fetch(&qu ...

Selenium web scraping yielding different results than displayed on the user interface

Last week, User @KunduK was generous enough to assist me in scraping a website to retrieve the address of a specific record. The record in question can be found at this link: We used the following code snippet: address=WebDriverWait(driver,10).until(EC.vi ...

In Node.js, when accessing a Firebase snapshot, it may return a

Currently, I am utilizing Firebase functions to execute the code for my Flutter application. This code is responsible for sending push notifications to my app. However, I am encountering an issue where I receive a null value at snap.val(). Take a look at h ...

retrieving the outcome from a PHP script invoked through Ajax

Having trouble transferring the results of a PHP script to HTML input fields This is my PHP script: $stmt->execute(); if ($stmt->rowCount() > 0){ $row = $stmt->fetch(PDO::FETCH_ASSOC); echo 'Located: ' . $row[&ap ...

Extracting the text content of a specific tag while ignoring the text within other tags nested inside the initial one

I am trying to extract only the text inside the <a> tags from the first <td> element of each <tr>. I have provided examples of the necessary text as "yyy" and examples of unnecessary text as "zzz". <table> <tbody> <tr ...

What are the steps to start a ExpressJS server for webpages that are not index.html?

I am exploring how to browse/run/view web pages other than just the index.html file in my public folder, which contains multiple HTML files. I am using ExpressJS and NodeJS for this purpose, but every time I start my server, I can only access the index.htm ...