Skip to Main Content
Mastering Selenium WebDriver 3.0 - Second Edition
book

Mastering Selenium WebDriver 3.0 - Second Edition

by Mark Collin
June 2018
Beginner to intermediate content levelBeginner to intermediate
376 pages
8h 58m
English
Packt Publishing
Content preview from Mastering Selenium WebDriver 3.0 - Second Edition

Executing complex blocks of JavaScript with the JavascriptExecutor

First of all, we need to write some JavaScript code that can simulate the events that we need to trigger to perform the drag-and-drop action. To do this, we are going to create three JavaScript functions (note that these three functions are not Java code). The first function is going to create a JavaScript event:

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; 
} 

We then need to write a function that will fire event instances ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Selenium WebDriver 3 Practical Guide - Second Edition

Selenium WebDriver 3 Practical Guide - Second Edition

Pallavi Sharma, UNMESH GUNDECHA, Satya Avasarala

Publisher Resources

ISBN: 9781788299671Supplemental Content