Beginning with Selenium 3.0 Automation – Part IV (Scripting with Selenium 3.0)

Beginning with Selenium 3.0 Automation – Part IV (Scripting with Selenium 3.0)

 

Hey Folks, you are all set to begin with the Selenium scripting.

There are few things to begin with.

  • Reference to be set to the Selenium class for inheriting WebDriver properties.
  • This is done by

Import org.openqa.selenium.WebDriver;

Import org.openqa.selenium.firefox.FirefoxDriver;

Remember you had created a class called as “My_Class”. Now we expand it.

Your first class - My_Class
Your first class – My_Class

 

 

 

 

 

 

 

 

With this class in place, let’s now run the script.

Oh!!! you have an error. We need to understand this to proceed further.

An Error!!!

Your first script - Error
Your first script – Error

 

 

 

 

 

 

 

What is this error? How to set it right?

  • We had seen some moments back that Selenium Webdriver uses the geckodriver for the Firefox browser.
  • So we need to download and install it to the right path.
  • Let’s see how to do it.

 

Hey, we got the solution!!!

  • Download geckodriver from the given URL.

https://github.com/mozilla/geckodriver/releases

  • Important – Ensure that you have the right geckodriver to your selected browser, or else the script wouldn’t work at all.

So there we are. We have now downloaded and saved the geckodriver to the “Drivers” folder.

We have the right geckodriver in the drivers folder
We have the right geckodriver in the drivers folder

 

 

 

 

We need to return back to our script and modify it accordingly to reference it to the geckodriver.

Our class script - modified for geckodriver
Our class script – modified for geckodriver

 

 

 

 

Let’s run our script. Hurrah!!! We have done it.

The script runs and we have a successful test script run.

Selenium Script - successful run for modified geckodriver
Selenium Script – successful run for modified geckodriver

 

 

 

 

 

 

Now our script runs, but we have more to do.

We have to carry out actions based on our script; so let’s take it a step further.

  • We will identify elements and perform action on these elements.
  • Point to the element, right click and select “Inspect Element”.
Inspect Element on your browser
Inspect Element on your browser

 

 

 

 

 

Inspect Element - Identify your appropriate attribute for the inspected element
Inspect Element – Identify your appropriate attribute for the inspected element

 

 

 

 

 

Now that we have identified the element on which action needs to be performed and we have also got the right attribute. It could be any of the following

  • id
  • name
  • xpath

We modify the script accordingly and viola!!! it is done…

Script modified to point to the right element
Script modified to point to the right element

 

 

 

 

 

Another modification to the script to illustrate the use of the ENTER key.

Script updated to reflect the SENDKEYS for the ENTER Key
Script updated to reflect the SENDKEYS for the ENTER Key

 

 

 

 

 

 

You should be ready to take off and go round the world with Selenium scripting.

Happy Selenium Scripting!!! 🙂

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s