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

Selenium GUI tests are not showing up when running in Jenkins on a Windows 7 machine

I am encountering an issue where when I run my Selenium test (mvn test) from Jenkins on a Windows system, I can only see the console output and not the actual browsers being opened. Is there a way to configure Jenkins so that I can view the browsers runn ...

Soft keyboard on mobile fails to update when arrows are used in Ajax-populated dropdown menus

I am working on a web form that includes two select fields: Country and City: <select id="country" onchange="getCity(this);"> <option value="">-- Please select your country --</option> <option value="1">Austria& ...

Selenium in chrome does not support automatic translation

Whenever I use Selenium WebDriver in Chrome to open a webpage in a foreign language, it doesn't translate the page to English automatically. Is there a way to change this behavior? Interestingly, when I manually open the same page, it does get tran ...

The functionality of Selenium's IJavaScriptExecutor appears to be malfunctioning

It seems like I am having trouble getting IJavaScriptExecutor to work properly in Selenium. Could it be possible that there have been some changes made to the library and I am not referencing it correctly? However, I can confirm that there are no syntax e ...

PHP and AJAX allow for seamless data retrieval without the need for page refreshing, and the data can be easily displayed in a modal window

I am currently encountering an issue with sending data to another page without refreshing. I am able to send the data as text, but for some reason, I am unable to send it as a modal. Why might this be happening? Here is an image of my current page https:/ ...

Ensure the date is displayed in the format of dd-mm-yyyy when using the input type=date

Here is the code I am currently using : <input type="date" class="form-control" id="training_date" name="training_date" placeholder=" select" value="" onfocus="(this.type='date')" onfocusout="(this.type='date')" max=<?php echo ...

Determine the active animation on an element using jQuery or JavaScript

Can you provide the code for the know_anim() function that can determine which animation is currently running on the '#div' element? Check out the jsFiddle link for reference:https://jsfiddle.net/himavicii/bL0nsjeL/ function moveLeft() ...

Utilizing AJAX to send RSS feeds to a Django view

I'm fairly new to using ajax. Here's the scenario I'm dealing with: I'm working on a side project that involves displaying news and scores for various sports. To achieve this, I'm utilizing rss feeds from different sources. In my D ...

Choose a navigation item from the list containing a nested span element

I've implemented selectnav from GitHub and it's functioning perfectly. However, my menu consists of list items with a description span inside each one, resulting in menu items structured as shown below: <li><a href="somelink.html">Ch ...

What is the best way to configure AngularJS for optimal integration with Google Maps services and functionalities in an "angular way"?

I'm currently working on a new app that utilizes the Google distance matrix, directions service, and various map features such as custom markers. I'm curious - where do you think is the best place to house all of this different functionality? Sho ...

The event listener for 'load' is not functioning properly within the React (Gatsby) environment

I'm having trouble with a sticky scroll parallax effect when the page initially loads at a position other than the top. I'm utilizing the react-scroll-parallax library (https://www.npmjs.com/package/react-scroll-parallax). To address this issue, ...

Sending information (prop) from _app.js to getServerSideProps in a page on the most up-to-date version of NextJS

I have a unique custom _app.js that I created: const CustomLayout = ({ children }) => (children); const myApp = ({ Component, pageProps }) => { pageProps.url = 'another url'; return ( <CustomLayout> <Co ...

Incorporating nested maps in JSX for efficient data manipulation

{normalizedData.map(item => <div key={item.display_date_numberic}> <div>{item.display_date_numberic}</div> </div> {!isEmpty(item.applicants) && item.applicants.map(applicant => <div className= ...

Troubleshooting issues with JavaScript progress bar functionality

I have implemented a progress bar using HTML5, JavaScript and Ajax to showcase file uploads in PHP. The issue I am facing is that the progress bar is not displaying the progress correctly. In addition to that, the echo statements in the PHP code are no ...

Choosing the Offspring: Deliberating on Multiple Children with Identical Names in Selenium

Just starting out with Selenium and web development in general, I've encountered a problem with locating an element using XPath. selenium.common.exceptions.NoSuchElementException I've been trying to troubleshoot for a while now, but haven' ...

jQuery's Multi-Category Filter feature allows users to filter content

I have been working on creating a filter function for my product list. The idea is that when one or more attributes are selected, it should fade out the elements that do not match. And then, if a filter is removed, those faded-out items should fade back in ...

The combination of a modal box, checkbox, and cookie feature creates

I am trying to accomplish the following tasks: When the homepage loads, I want a modal box to appear Inside the modal box, there should be a form with a mandatory checkbox After checking the checkbox, submit the form and close the modal box to return to ...

Leveraging the JavaScript NPM module through import functionality

Currently, I am utilizing the kahoot-api NPM module (GitHub, NPM) that requires JavaScript import. (edit: this is a Node.js package. At the time of writing this, I was unaware of the distinction between JS and Node.js, hence the creation of this question). ...

Iterate through and append to a list

My current goal is to create a list of URLs named visit_urls that I need to visit. To begin with, I manually provide the first URL to be visited using self.br.get(url). By determining the number of pages on the website, let's say it has 40 pages, I ca ...

Searching for a specific key and its corresponding value within an Object Literal (JSON string / object) is necessary

After reading up on JSON objects , I am now trying to locate the value associated with a specific KEY, which may be null, no or yes. The KEY in question is "f03eb90f-6b5e-4b26-bd9f-bad788b7edac" and I want to retrieve its value You can find the Fiddle ...