The functionality of drag and drop in Chrome 91 seems to be unresponsive when utilizing Selenium WebDriver, Action Class, and JavaScript

Recently, I have encountered an issue with the drag and drop functionality in Chrome version 91 while using Selenium Action class or Java script. Despite trying various approaches, including:

  1. Using a custom JavaScript method for drag and drop.

JavaScript Method 1

// Custom JavaScript function for drag and drop
function customEvent(typeOfEvent) {
    var event = document.createEvent("CustomEvent");
    event.initCustomEvent(typeOfEvent, true, true, null);
    event.dataTransfer = {
        data: {},
        setData: function (key, value) {
            this.data[key] = value;
        },
        getData: function (key) {
            return this.data[key];
        }
    };
    return event;
}
// Function to dispatch the drag and drop events
function dispatchEvent(element, event, transferData) {
    if (transferData !== undefined) {
        event.dataTransfer = transferData;
    }
    if (element.dispatchEvent) {
        element.dispatchEvent(event);
    } else if (element.fireEvent) {
        element.fireEvent("on" + event.type, event);
    }
}
// Function to execute drag and drop operation
function executeDrageAndDrop(element, target) {
    var dragStartEvent = customEvent('dragstart');
    dispatchEvent(element, dragStartEvent);
    var dropEvent = customEvent('drop');
    dispatchEvent(target, dropEvent, dragStartEvent.dataTransfer);
    var dragEndEvent = customEvent('dragend');
    dispatchEvent(element, dragEndEvent, dropEvent.dataTransfer);
}

JavaScript Method 2 :

// Another custom JavaScript function for drag and drop
function createEvent(typeOfEvent) {
var event =document.createEvent("CustomEvent");
event.initCustomEvent(typeOfEvent,true, true, null);
event.dataTransfer = {
data: {},
setData: function (key, value) {
this.data[key] = value;
},
getData: function (key) {
return this.data[key];
}
};
return event;
}

// Continuing code here... 

  1. Attempting drag and drop using jQuery method.

     // jQuery simulate plugin code snippet for simulating mouse and keyboard events
    (function( $, undefined ) {
    // Code snippet continued here... 
  2. Exploring drag and drop option through Robot Class.

    Locatable element = (Locatable)sourceElement ;
    Point p= element.getCoordinates().inViewPort();
    int sourceX=p.getX();
    int sourceY=p.getY();
    
    // Further steps using Robot class for simulation...
  3. Utilizing Selenium Touch Actions for drag and drop operations.

    TouchActions builder = new TouchActions(driver);
    builder.longPress(sourceElement).moveToElement(destElement).release(destElement).perform();

Despite these attempts, none of the solutions worked for me. Drag and drop feature was functional on earlier Chrome version 89.

Check out the highlighted source & target elements in the attached screenshot.

If you have any insights or solutions, please feel free to share. Your help would be greatly appreciated!

Answer №1

To solve the issue of mouse over click, you can try using the offset method as shown below:

    Locatable elementLocation = (Locatable)element ;
    Point p= elementLocation.getCoordinates().inViewPort();
    int sourceX=p.getX();
    int sourceY=p.getY();
    new Actions(driver).moveByOffset(sourceX, sourceY).click().build().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

Avoid duplicate calls to the same URL in node.js

I need to make multiple calls to the back-end with some of them targeting the same URLs. To optimize performance, I am caching the results. However, a problem arises when I call loadCached twice in quick succession with the same URL - it ends up triggering ...

Tips for selecting multiple spans on a webpage to extract additional information with Selenium in Python

I am attempting to extract information on broadband deals for a specific postcode "NE8 1SR" from the website . Specifically, I need details such as the plan name, price, download speed, and upload speed. This information is visible after clicking either ...

Using Vue router meta title with a passed parameter

I'm faced with the challenge of creating a dynamic title for a Vue route. Unfortunately, I haven't been able to figure out how to pass a parameter into the meta title. This is crucial for me because my VueHeader component relies on the route meta ...

Enhance Your HTML Skills: Amplifying Table Display with Images

Recently, I utilized HTML to design a table. The Table Facts : In the first row, I included an appealing image. The second row contains several pieces of content. In continuation, I added a third row. The contents in this row are extensive, resulting i ...

creating a value and finalizing on the yield operation

Despite my attempt to use es6 generators to set the value/done as I want, I am struggling to achieve the desired outcome. Whenever I try to set a value, it ends up in the "value" field, while the generator always returns "done: false" when I am actually ai ...

Using Selenium's click() function will highlight the button, but it does not actually perform the click action

As I delve into using Selenium with Python for a Robotic Process Automation project, encountering obstacles when it comes to clicking on a specific button. Oddly enough, manually clicking the Search button yields no results, but utilizing Selenium triggers ...

What is the best way to prevent redundancy in object repository creation for Selenium testing?

Currently, I am working on automating a process that requires me to repeatedly write xpath for various elements. I am looking for guidance on how to establish a centralized repository to efficiently access these xpaths from my Java code. ...

Tips for navigating through elements generated with ng-repeat as I scroll

There is a list generated using ng-repeat along with two buttons for moving up or down. Users have the option to select any item from the list and utilize the buttons to navigate through it. However, when I lower the selected item using the "go down" butt ...

What should I do if one of my images fails to load after the previous one has loaded successfully?

My code is designed to create an animation using 3 canvases: one for the base image, one for the streamline wind map drawing, and another for an image covering part of the drawing. The following code displays the uploading of two images. var im ...

Enhance Object within one function using another function to increase its worth

How can I update the value in a chaseObj from a method in another object? Any advice would be greatly appreciated. Thank you! var s, searchUts; var getValue = ''; var generateObject = function() { var chaseObj = { "timeFilters" : getValue ...

Changing pages without refreshing is a beneficial habit to adopt

Looking for a way to switch pages without any reloading? Here's my AJAX approach: app.ajax.client.request = function(headers, path, method, queryObj, payload, cb) { // Code for sending AJAX request goes here } Client Requests: app.changeToInd ...

Performing an AJAX request to the database when a change occurs, prior to submitting the

In my user setup/create form, I am including a field for the users' license/certification number which needs to be validated and returned to a specific DIV Onchange before the form is submitted. I have heard that using AJAX POST is the way to achieve ...

Issues with Nuxt Authentication when deployed live

Attempting to deploy a nuxt application on a server with nginx acting as a proxy to localhost. Everything seems to be functioning properly; the application can be accessed using the server's domain and API calls can be made to the server. However, aut ...

Retrieving user input from a designated form using its name in JavaScript

When PHP constructs a form with jQuery and AJAX retrieves it to the current page, all input elements end up having identical names and IDs. While the forms themselves have unique IDs, I am struggling to reference the specific form and its duplicate input I ...

Vue and Vuetify tutorial: Implementing validation for individual chip items within a select input instead of the entire input field

Is there a way to implement validation (using vee-validate) on each individual chips item? Below is the current code snippet: <v-select class="elevation-0 mt-border-bottom" v-model="PhoneNumber" label="Add phone number" chips tags solo p ...

Using VBA with Selenium to target a specific button hidden within a series of div tags

As I worked with selenium in VBA, I encountered a challenge on the current webpage. My goal was to instruct the bot to select the ID named "exportbutton," but all my attempts using FindElementByXPath have resulted in an error stating that the ID cannot be ...

JavaScript preloader failing to wait for images to load

I came across this Javascript code to enable the pre-loader on my website. However, I noticed that it disappears as soon as the page loads, instead of waiting for all images to finish loading. After some research, I found a suggestion to use window.onload ...

Leveraging JavaScript Variables with Android Development

How can I extract a JavaScript variable from a website and incorporate it into my code? I followed the steps in this guide to display the string in an alert message, but now I'm unsure how to use it outside of the alert. Any advice would be appreciate ...

Is there a solution to fix the issue with IE causing hover effects not to

I'm currently in the process of designing a website, and I have implemented some image hover effects that reveal elements within the image when you hover over it. These effects are functioning correctly on Chrome, Safari, and Firefox; however, they ar ...

What could be causing the issue of dynamic values not getting submitted from a form in NextJS?

In my current project, I am utilizing React within a NextJS framework. When I manually input values into form fields and submit the form, I am able to access all the values in the component function. However, when I populate a form field dynamically usin ...