Prevent the blocking of Selenium Webdriver by halting the execution of

I am currently facing challenges while writing tests for a web application using Selenium with Ruby.

During my automated test, the selenium webdriver triggers a click on an element that executes some Javascript code.

This Javascript creates an alert window, which I usually handle by accepting it like this:

@IE.switch_to.alert.accept

However, in this scenario, the control is not returned to the Webdriver after triggering the alert, making it impossible for me to accept it.

It seems like the Javascript is still running and waiting for the alert to be accepted before completing its execution.

Since the Webdriver requires the Javascript to finish executing first before handling the alert, I am stuck in a situation where the alert cannot be accepted, and the Javascript will continue to run indefinitely.


Unfortunately, I do not have permission to modify the Javascript code, so the solution needs to come from the Selenium side.

Is there any way to execute the Javascript without making the Webdriver wait?

----UPDATE 1-----

Following a suggestion from a commenter, running the Javascript in a separate thread allowed me to regain control over the Webdriver: ************WRONG -- SEE UPDATE 2*******************

Thread.new{
  button.press
}

However, I am unable to handle the alert as usual:

@IE.switch_to.alert

The above method is not working.

----UPDATE 2-----

Even when running the Javascript in a separate thread, its execution still blocks further actions by the Webdriver.

I am utilizing Selenium Grid to run tests remotely.

This means I cannot send keystrokes or any signals to the remote PC unless those methods are provided by the remote Webdriver. Moreover, since the Webdriver gets blocked by the Javascript even when executed in a separate thread, communication with the remote PC becomes impossible once the alert pops up.

One possible solution could be similar to what Murali suggested below - overriding the Javascript methods with ones that do not trigger alerts. However, this solution is not ideal as the Javascript methods I would need to override are complex and lengthy.

If anyone has insights or suggestions on how to tackle this issue, it would be greatly appreciated as it is hindering progress on our project.

Thank you!

Answer №1

If you are familiar with the function that activates the alert, you can attempt to disable it using a JavaScript executor. Here is an example:

((JavascriptExecutor)driver).executeScript("window.alert = function(msg){return true;};");  

Best regards, Murali

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

What is the best way to manage an empty JavaScript object?

I'm feeling stuck. Check out this code snippet: const clientInfoPromise = buildPromiseMethod clientInfoPromise.then((clients) => { console.log('clients ' + JSON.stringify(clients)) console.log(clients.typeOf) console.log(_.k ...

How come the back button does not initiate client-side navigation in a Next.js application?

In my Next.js application utilizing GraphQL to fetch articles from a server, I encountered an issue with dynamic routing when reloading the page while on an article and attempting to navigate back. The usual scenario works as expected: Index -> [slu ...

Encountering a Typescript issue stating "Property 'then' does not exist" while attempting to chain promises using promise-middleware and thunk

Currently, I am utilizing redux-promise-middleware alongside redux-thunk to effectively chain my promises: import { Dispatch } from 'redux'; class Actions { private static _dispatcher: Dispatch<any>; public static get dispatcher() ...

Transferring information via a function to a modal component in VueJS

Seeking advice on passing data to a modal. I'm attempting to pass data to a modal, where a function within a v-for loop gathers the video URL for later opening. The modal is placed outside the v-for loop to prevent all videos from playing the same o ...

Appium and Protractor can successfully launch the application, however, they are unable to interact with any elements within the app

After developing a mobile test framework using appium and protractor, I encountered an issue where the app opens but fails to perform any actions. Versions: Appium - 1.6.5 Protractor - 1.5.2 Here are the Appium error logs: [HTTP] <-- POST /wd/hub/se ...

display or conceal a div when a radio button is selected

I need a way to display a specific div containing unique text once a radio button is selected, while hiding all other div sections. <?php foreach ($items as $item){ $i=1; echo ' <div class="form-check"> <input class="fo ...

Customize the Material UI InputBase component using date and time pickers styling

I have been working on customizing a date time picker option in material ui. After creating a styled Input that I liked, I attempted to use it as a base for my design. When I added the type="datetime-local" prop to the component, it provided the ...

In Chrome Inspector console, a never-ending JavaScript loop is triggered by a modification in the htaccess file to create pretty URLs, specifically when

Brand new to the world of .htaccess modifications and handling clean URLs. I currently have a php/bootstrap/mysql/javascript page at: http://localhost/modules/posts/questions_all.php. I am interested in redirecting pages such as http://localhost/modules/ ...

Design a logo to serve as the main button on the navigation bar of the

I've been experimenting with adding a logo instead of the 'Home' text in my navigation bar, but I'm not sure where to implement it. Should I add it within #nav or separately? Also, I want the nav bar to stay fixed without overlapping on ...

What's the best way to vertically center a div with a 100% width and a set padding-bottom on the screen?

I am struggling with positioning the following div on my webpage. .div { width:100%; padding-bottom:20%; background-color:blue; } <div class="div"></div> I have been searching for a solution to vertically center this responsive div on my web ...

Conceal the year, month, and day within a datetime-local input

I am working with <input type="datetime-local" step="1"/> input fields, and I want users to only be able to edit the hours, minutes, or seconds. This is due to setting the minimum value using let min = new Date().setHours(0,0,0) and the maximum value ...

Mastering the art of utilizing drag and drop features for both columns and rows in a React Table within ReactJS

I have managed to create a React Table with columns and rows, but now I'm looking to incorporate drag and drop functionality for both. Does anyone know how I can achieve this? Feel free to check out my CodeSandbox Sample here - https://codesandbox.io ...

Information is not appearing in the table

I'm having trouble displaying data in a table format. The issue arises when I try to fetch data from a JSON file using a custom service. The fetched data is then inserted into the $rootScope object. However, when I preview the view, it appears blank ...

Hide and show submenus with jQuery while ensuring that the initial submenu remains visible, along with the main menu

I am struggling to figure out how to make the first message active by default along with its corresponding menu selection in my navbar. I have implemented a show/hide functionality on the main menu click, but currently only the menu is being set as active ...

I'm facing issues with Angular commands not functioning properly even after installing the Angular CLI and configuring the

Every time I attempt to create a new project using Angular CLI by typing: ng n app I encounter the following error message: C:\Users\Venkateshwarn M\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng: ...

Having Trouble with the JSX React HTML5 Input Slider

I'm currently utilizing React.JS for a project, where I am creating a range input slider with two options as part of a component. This is the code snippet in question: <input id="typeinp" type="range" min="0" max="5" value="3" step="1"/> Upon ...

When the React functional component changes its state, it triggers the un-mounting and re-mounting of its parent

I created a functional component that allows for toggling the visibility of a password field using a small button that switches between closed and opened eye images. The issue I'm facing is that even though the parent does not have any affected state ...

Unable to access remote video streams by directly modifying URL parameters

Recently, I delved into experimenting with the straightforward mediasoup demo available at: https://github.com/Dirvann/mediasoup-sfu-webrtc-video-rooms After setting up the demo, everything seemed to be functioning correctly. The initial task on my agend ...

Utilizing data attributes to configure jQuery plugin settings

Having trouble assigning options to an array value in a jQuery plugin using data attributes. When referencing the data attribute with a class selector: $('.tm-input').tagsManager( { prefilled: $('.tm-input').data('loa ...

One function is failing to execute properly due to multiple if conditions

Take a look at my JavaScript code below: function showLater1() { if ((vidos.currentTime >= 30) && (vidos.currentTime <= 34)) { lay.style.opacity = "1"; content.style.opacity = "0"; controls.style.opacity = "0"; ...