Monday, July 23, 2012

Selenium Module #6 ( Javascript)


For creating user extensions in Selenium IDE, it is necessary to learn javascript as Selenium core is in javascript.

So, lets start learning javascript.

Javascript is a scripting language which is embedded directly into HTML pages and works at client's browser. It supports different browsers- IE, Mozilla Firefox, Google Chrome, Safari , Opera.

 Features of javascript 

1. Detects visitor's browser- Because of this platform dependent functions can be easily performed by the script. This ensures loading of page designed specifically for that browser.

2. Validates data- If user commits any mistake while inputting data then error message will be popped up.

3. Creates cookies- Used to store and retrieve information on visitor's computer.

4. Manipulates HTML elements- Some contents dynamically changes after clicking some icons like arrow. This is because of the javascript operation on client machine.

5. Easy programming tool- It is an object oriented language with simple syntax.

Javascript programs

If you are having a basic understanding of html then it will be easier to understand javascript. Lets have a look at simple javascript program

<h1> My first javascript program </h>  //Heading
<script type =" text/javascript"> //script tag for inserting javascript into HTML
document.write("<p> Good Morning </p>"); //print text on web page

My first javascript program
Good Morning

Above program is executed when page is loaded. However if we want to run our program when some event is generated like clicking some button, we use functions:

<script type="text/javascript">
function javascriptFunction()
document.getElementById("demo").innerHTML="My First JavaScript Function";


<h1>Javacript Function</h1>

<p id="demo">Welcome to</p>

<button type="button" onclick="javascriptFunction()">Click me</button>


Following output will be displayed

On clicking Click me button,
it will display:

To be continued...

No comments:

Post a Comment