JavaScript introduction for web automation using Selenium
In this article I'll be talking about some of the JavaScript details which are required for Selenium web automation and how the JavaScript is being used by selenium to automate browsers. Also, about some of the browser object models and document object models which are required for our automation testing.
JavaScript is a high-level, dynamic, untyped and interpreted programming language. JavaScript is one of the three essential technologies of worldwide web content productions and majority of sites have JavaScript running on it. The other two essential technologies of world wide web are HTML and CSS. JavaScript runs without any plug-ins, meaning you don't have to install any special plugin on your browser to run JavaScript. Now let's look into the relationship between Selenium and JavaScript, as we already know that Selenium Webdriver behind the scenes converts the client code. Client code or language binding is the code you write in either C# or Java or Python or Ruby or any other programming language to execute automation of your browser. It will be converted into JavaScript by your Selenium Webdriver and this JavaScript will be injected into the browser's like i.e, Chrome and Firefox. So, Selenium and JavaScript are closely connected and we can perform whatever operation Selenium performs using JavaScript itself. We can get the tags or we can identify a control or perform an operation on a control.
To under the concept better we need to know about the following JavaScript libraries the JavaScript HTML document object model(DOM) and JavaScript browser object model(BOM). Some of the examples of the JavaScript are:
We can use these commands directly on a browser's web developer tool or a locator identifier tool like fire bug and run the commands directly to execute the same operation performed by Selenium. Sometimes when Selenium Webdriver is not successful in performing an operation on a website we can call JavaScript Executor in Selenium and perform the JavaScript command directly from Selenium. I'll talk more about it in my next article.