by admin | Apr 22, 2017 | Automation Testing, Fixed, Blog |
In this blog post, you will learn how to read Excel file using JavaScript. exceljs – JavaScript Excel Library reads, manipulates and writes spreadsheet data and styles to XLSX and JSON.
We have used Apache POI, Fillo, JXL, and pyxll Excel Java & Python libraries for automation testing services. However, Reading and manipulating Excel file in JavaScript is very interesting.
Installation
You can install exceljs Excel Workbook Manager with the below npm install command.
`npm install exceljs`
Code
//Read a file
var workbook = new Excel.Workbook();
workbook.xlsx.readFile("data/Sample.xlsx").then(function () {
//Get sheet by Name
var worksheet=workbook.getWorksheet('Sheet1');
//Get Lastrow
var row = worksheet.lastRow
//Update a cell
row.getCell(1).value = 5;
row.commit();
//Save the workbook
return workbook.xlsx.writeFile("data/Sample.xlsx");
});
You can also read and write CSV file. Refer: Reading CSV and Writing CSV
by admin | Mar 10, 2016 | Automation Testing, Blog |
This is our very first article in Selenium, we hope it is helpful for Selenium users. Keep visiting Codoid blogs for more articles in the near future.
Using Custom JavaScript Mouse-event
//The below JavaScript code creates, initializes and dispatches mouse event to an object on fly.
String strJavaScript = "var element = arguments[0];"
+ "var mouseEventObj = document.createEvent('MouseEvents');"
+ "mouseEventObj.initEvent( 'mouseover', true, true );"
+ "element.dispatchEvent(mouseEventObj);";
//Then JavascriptExecutor class is used to execute the script to trigger the dispatched event.
((JavascriptExecutor) driver).executeScript(strJavaScript, element);
Using Device
//Getting mouse from driver object
Mouse mouse =((HasInputDevices)driver).getMouse();
//Invokes mouseMove method by passing element coordinates as argument
mouse.mouseMove(((Locatable)element).getCoordinates());
Using Advanced User Interactions API
Actions builder = new Actions(driver);
builder.moveToElement(element).perform();
//Note: (Preferable for Firefox and HTMLUnit drivers)