Internet Explorer freezing when running selenium executeScript

Hey everyone, I've spent the past couple of days scouring the internet trying to find a solution to my modal dialog problem. There's a wealth of helpful information out there and everything works perfectly fine except for Internet Explorer. Specifically, I'm facing an issue when attempting to open a file upload dialog and select a new file. I've created autoIT scripts that work flawlessly with Firefox and Chrome, but encounter a roadblock with IE - the "executeScript" doesn't return back to my test scripts after opening the file upload dialog in IE. Strangely enough, running the autoIT script manually allows it to return back to the test script once the file upload dialog closes.

//WebDriver driver = new FirefoxDriver();
// processPage(driver);
WebDriver ieDriver =new InternetExplorerDriver();
processPage(ieDriver);
// WebDriver chromeDriver = new ChromeDriver();
// processPage(chromeDriver);

. . . other code . .

WebElement element = driver.findElement(By.name(uploadDifferntFile));
if (driver instanceof InternetExplorerDriver) {
  ((InternetExplorerDriver) driver).executeScript("arguments[0].click();", element);

} else if(driver instanceof FirefoxDriver){
  ((FirefoxDriver) driver).executeScript("arguments[0].click();", element);

} else if(driver instanceof ChromeDriver){
  ((ChromeDriver) driver).executeScript("arguments[0].click();", element);

}

. . . autoIT . . .

try {
    Process proc = Runtime.getRuntime().exec(fileToExecute);
} catch (IOException e) {
    System.out.println("Failed to execute autoIT");
    e.printStackTrace();
}

Appreciate all the support provided by you guys!

Answer №1

It appears that the issue may be linked to a modal dialog being triggered during the operation of argument[0].click in Internet Explorer. You can refer to this link for more information on handling clicking elements and submitting forms with alert() in Selenium.

Here are a few suggestions to consider:

  1. Try replacing your current code with either "element.click()" or "element.sendKeys(Keys.ENTER)" using JavaScript.
  2. Before executing argument[0].click, initiate a new thread, pause for a moment in that thread, and then proceed with running AutoIt code.

You can also enhance your code by utilizing JavascriptExecutor to execute JavaScript only once:

WebElement element = driver.findElement(By.name(uploadDifferentFile));
if (driver instanceof JavascriptExecutor) {
  ((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);
}

Answer №2

After encountering the same issue with unstable sendKeys in Internet Explorer, I came up with a different approach using AutoIt.

When working with Firefox, I utilize JavaScript; for IE, I opt for double-clicking on the input field:

// fileInput represents the WebElement selected from the file input field
if (browser == "FF") {
    JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("arguments[0].click();", fileInput);
} else {
    Actions action = new Actions(driver);
    Action doubleClick = action.doubleClick(fileInput).build();
    doubleClick.perform();
}   

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

Express is throwing a TypeError because it is unable to access the property 'app', which is undefined

On my nodejs server running the express framework, I have been encountering a random error when making requests. The error occurs unpredictably, usually appearing on the first request and not on subsequent ones. It's challenging for me to identify the ...

Unable to successfully change the Span Class

My webpage has the code snippet below, but it's not functioning as expected. I have tried two methods to change the span's class attribute, but they aren't working. Could someone please help me identify where the issue lies? :) <script l ...

Arrange the keys of a map in ascending order, prioritizing special characters and their precedence

JavaScript ES6 Map Example: const map = new Map(); map.set('first', ['1', '2']); map.set('second', ['abc', 'def']); map.set('_third', []); map.set(')(*', []); map.set('he ...

Updating Hidden Field Value to JSON Format Using jQuery and JavaScript

var jsonData = [{"Id":40,"Action":null,"Card":"0484"}]; $('#hidJson', window.parent.document).val(jsonData); alert($('#hidJson', window.parent.document).val()); // displays [object Object] alert($('#hidJson', window.parent.doc ...

How can a loading circle be displayed upon clicking a button on a PHP website using JavaScript?

As a newcomer to the world of JavaScript programming, I'm facing a challenge that seems deceptively simple. My goal is to display a loading circle when a user clicks on an upload button, trigger external PHP code for image processing, and then make th ...

implementing automatic ajax requests when user scrolls

This is a piece of JavaScript code: $(window).scroll(function() { $.ajax({ type: "GET", url: "not_data.php", data: dataString, success: function my_func () { //show new name ...

Enzyme examination: Error - anticipate(...).find was not recognized as a function

What is the reason for .find not being recognized as a function in the code snippet below? import React from 'react'; import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import { AuthorizedRoutesJest } from ...

Using JS to switch between text and state in ToneJS

I am facing an issue with the text not displaying in the "play-stop-toggle" element, despite my limited experience with JS. My desired outcome includes: [SOLVED] The text in <div id="play-stop-toggle" onclick="togglePlay()">Play ...

Verify whether the type of the emitted variable aligns with the specified custom type

Currently, I am in the process of testing Vue 3 components using jest. My main objective is to receive an emit when a button is clicked and then verify if the emitted object corresponds to a custom type that I have defined in a separate file. Below is an e ...

Retrieving file format of the image

When using the application, the user has the ability to select an image. The gallery is initiated with the following code snippet: Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForRe ...

What is the best way to highlight selected navigation links?

Recently, I implemented a fixed navigation bar with relevant links on a website. The navbar includes a jquery script for smooth scrolling when clicked. However, I am struggling to add a selected class to the clicked link. Despite trying various solutions f ...

I'm having trouble connecting two files as instructed and encountering errors. Can someone please provide guidance on how to properly attach them?

I am encountering an issue when trying to call the DevideByZeroo method as it keeps displaying "cannot find symbol". Despite attempting to change it to super, I continue to receive errors. package CatchBlock; import java.util.Scanner; import java.util.In ...

Is there a way to create a timed fadeIn and fadeOut effect for a div using HTML and CSS?

I have a single div that initially displays text, and I want it to fade out after a specific time so that another div will then fade in. However, my attempt at coding this transition is not producing the desired result: $(function() { $(".preloa ...

How come the HTML page served by the express.js route isn't linked to a CSS stylesheet?

Recently, I've been working with a server.js file that imports a router const path = require("path"); const express = require("express"); const app = express(); const PORT = 8080; app.use(express.urlencoded({ extended: true })); app.use(express.jso ...

recursive algorithm utilizing an array as an argument

Currently, I am in the process of developing a function that extracts chest exercises from an array titled "chest". This particular function is required to randomly select multiple exercises, achieved by utilizing a random pointer. In order to avoid selec ...

What could be the reason for my code generating the error [$http:badreq]?

I'm currently attempting to retrieve JSON data from a certain URL and am having trouble getting it to work. Despite going through the Angular documentation and other resources, I still can't pinpoint the issue due to my limited experience with An ...

Unable to modify the selector to "Remove preview files" on click in PHP and JavaScript

During the process of uploading multiple files (using <input type="file" multiple/>) with preview image file and successfully removing the image preview and file data, I encountered a problem. The issue arises when attempting to change the selector ...

AngularJS $http get isn't functioning properly, but surprisingly $.ajax works perfectly

Recently delving into the world of AngularJS, I am facing a hurdle with $http functionality. In my factory setup below: app.factory('employeeFactory', function ($http) { var factory = {}; // Retrieving data from controller var emplo ...

Developing a basic search engine model

I have been struggling with this homework problem for quite some time. The assignment involves delving into search engine technology and creating two classes, namely Term and Document. In the Term class, we define a String attribute called 'word&apos ...

How can I divide a string using a particular character encoding error that is being received in Python?

I am currently using Selenium WebDriver to extract all text content from a Facebook profile, essentially performing data mining. I am encountering an issue when trying to parse by a specific character. Even though I encode it beforehand, I am still facing ...