I am feeling increasingly frustrated at the moment and I am hoping to seek assistance on stackexchange.
First and foremost, I must admit that I am not a seasoned Javascript developer, probably not even an experienced developer overall, but I do have some knowledge of basic scripting languages like C# and Java. For my current web automation script, I decided to venture into writing in Javascript, but now I am seriously contemplating starting over with a less confusing language.
Could someone please advise me on how I can ensure that my code is executed synchronously from top to bottom?
After spending countless hours googling, here are some attempts I have made:
- Added
#! /usr/bin/env node
at the beginning of line 1 and started it in the terminal using./app.js
- Converted every function to an
async
function - Used
await
on all methods
Despite these efforts, when I run the script, I encounter multiple instances of
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'isDisplayed' of undefined
and similar issues, indicating that Node is running some of my methods/functions asynchronously. These exceptions appear in the console long before the browser window is loaded.
The tools and versions I am using include: * selenium-webdriver 3.6.0 * Firefox 60.0.2 * node 8.10.0
This is a snippet of what my code looks like:
// JavaScript code goes here...
// More code sample provided...
In essence, as far as my understanding goes, I initiate the webdriver and Firefox with my async init()
function. Within this function, I utilize await for all the methods. Following the initiation of the webdriver/Firefox, I assign the Object variables to the locations (which I want to happen once the browser is fully loaded).
However, for some reason unknown to me, the script appears to execute all functions and code it encounters immediately after starting. It seems to wait until the browser has fully loaded last. Prior to the complete loading, I receive several UnhandledPromiseRejectionWarning
messages..
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'sendKeys' of undefined
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'click' of undefined
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'isDisplayed' of undefined
Any help or guidance on this matter would be greatly appreciated.