How to automate file upload in Internet Explorer using Selenium?

January 8th, 2012By WaikhomComputers/Internet,Programming,Web Development

Selenium is the most popular framework for web browser automation. We use selenium for automating our UI test cases. Selenium works perfectly fine in most web browsers with the exception of the obviously most problematic “Internet Explorer”. Although most of the features of selenium work fine with internet explorer, there are a few hiccups particularly associated with Internet Explorer e.g. capturing Screenshot, file upload, etc. Here I’ll be talking about automating the file upload feature in Internet Explorer using Selenium.

In Firefox, you can automate file upload by simple using the “selenium.type” method over the file selector.

Selenium.type("/input[@name=image_file]");

However, the type method doesn’t work in Internet explorer because of security restrictions. Internet Explorer doesn’t allow you to change the value of file inputs through JavaScript. So, I did a little research on how I can automate the process in Internet Explorer. There seems to be a few solutions to this problem but none of them really solved mine because all of the solutions are for those who are not using selenium RC or are not using RC server in a remote machine. In my case, selenium RC is located in a remote machine and all my java classes in a separate controller machine. This makes it difficult to invoke autoit scripts as it is mentioned in most of the available solutions. Some of the methods I tried are:

  1. Using selenium.attachFIle: Selenium has an api for automating file uploads and is provided as the attachFile method. However, this method is supported in Firefox only and doesn’t work with Internet Explorer.
  2. Using native keys to type in the characters: Selenium RC has apis for generating native keyboard events. This method can be used to automate keyboard events in the OS level and outside the web browser. I also tried this in Internet Explorer, but once I click the browse button and the file selector popups, selenium gets blocked and the keys could not be typed without manual intervention
  3. Using AutoIT with Selenium: One most popular method of automating the file upload is to use an autoit script in conjuction with selenium. However this also had it’s own problem. I couldn’t invoke the autoit script from my test script as I was running selenium RC in a remote machine. I found another interesting post about this method here – http://automationtricks.blogspot.com/2010/09/how-to-upload-file-in-selenium.html

THE FIX

After a series of trials, I could finally automate the file upload scenario in Internet explorer. The fix was to upgrade my selenium from 1.x to 2.x (or webdriver). Unlike selenium 1.x, webdriver is not javascript driven and is not as restricted as javascript driven selenium 1.x. However, upgrading from 1.x to webdriver was a mess because all my test cases were then not working as expected in firefox. So, i did a little hack here to make sure web driver is used only in case of Internet explorer. Given below are the changes I made.

Before:

DefaultSelenium selenium = new DefaultSelenium("localhost",4444,"*iexplore","http://www.example.com");
selenium.start();

After:

WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),DesiredCapabilities.internetExplorer());
DefaultSelenium selenium = new WebDriverBackedSelenium(driver,"http://www.example.com"));

With this code change, we are now using web driver backed selenium, and because of this, the selenium.type method can be used without any security restrictions. As a result, my file upload automation was run successfully. Well, thanks to those guys working on web driver.

In fact, many of the limitations of selenium 1.x have been addressed by web driver and there’s a properly documented section on migrating selenium 1.x to webdriver. If you are facing any issues with selenium 1.x, you might try upgrading to web driver. More details on the upgrade process are available here – migrating from selenium 1.x to web driver. Well, if you find anything interesting, feel free to share it here.

Kontera and slow wordpress

October 24th, 2011By WaikhomComputers/Internet,Web Development

For quite some time, my blog has been slow and I finally got the time to sort this out. Using Firebug, I analyzed the page response times of all requests made while opening my homepage. And surprisingly, the kontera ad code that I added seems to be taking a lot of time. So, I just removed the ad code and tried refreshing my page and then …oorah.. My blog is loading faster than ever before.

But then, what about the bucks I get from kontera? I went to their site and just checked my last quarter earnings and it was pathetic. Who’s gonna sacrifice the speed of their blog for a few bucks a quarter. Maybe i’ll try something like infolinks but not kontera. Not anymore. Well, if you have kontera and your blog is taking too much time, removing the kontera ad code is the first thing I’ll suggest you to do. And after that, you can start looking for “i like taking time to load” plugins in firebug.

How to earn money with Squidoo!

March 12th, 2010By WaikhomComputers/Internet,Web Development

Squidoo is a content publishing platform and community that makes it easy for you to create “lenses” online. Lenses are web-pages created by people like us. Earlier Squidoo lenses used to be consisted of only text contents and users used to create static pages for promoting their sites. But now, Squidoo has evolved into a new generation platform which has integrated system for users to earn money directly from Squidoo. Squidoo has many features and modules from which users can earn money like amazon, ebay, textlinkads, etc. Today, we’ll have a look at how you can earn money from your squidoo lenses without even having your own website or ebay account.

I just created a squidoo lens on proxy sites just to promote my sites. But I found out that squidoo has lots and lots of stuffs from which you can earn constantly. If you go to the proxy sites lens on squidoo, you will find out a section which consists of amazon products for sale. When some reader clicks on this sale and buy it, Squidoo earns the commission from amazon and shares its earnings with you. Similarly, there are other modules like Ebay, donations, etc. which can let you earn commissions when users buy through your lens.

So, how do you earn from squidoo? All you have to do is to have a Paypal account. Create a Squidoo lens on some topic and add the modules amazon, ebay and donations. Now, you can start promoting your squidoo lens by sharing it with your fiends on digg, stumbleupon, twitter, etc. The more visitors you have, the more earnings you will have. So, try it out and start earning online. Well, its all for free, so you don’t have to worry at all.

Namecheap Coupon Code for January 2009

January 2nd, 2009By WaikhomWeb Development

Happy New Year to You All! With the coming of 2009, the coupon code of namecheap has changed and you need a new coupon code for buying domains at namecheap.com. So, I’m bringing you the latest coupon code for namecheap and is for the whole month of January 2009. Well, this coupon will help you buy your domains at a reduced price of $8.81 instead of its original price of $9.69. The coupon code for January is given below:
Coupon code: HAPPY2009
Expires on: 31st Jan 2009
Hope this helps you guys save your money while buying your domains from namecheap. Enjoy :) .

Top 25 Essential WordPress Plugins for wordpress 2.7

December 17th, 2008By WaikhomWeb Development,Wordpress Plugins

Top 25 essential wordpress plugins or Top 20 wordpress plugins or wordpress plugins have always been a topic of question for many bloggers using the wordpress platform. At this moment there are around 3550 wordpress plugins out of which you wouldn’t possibly use more than 40 at most. But which 40 plugins will you choose amongst these numerous plugins will depend on your blog’s nature and topic. However, there are a few plugins which are needed by almost every pro blogger. I know that such lists have been made by a number of bloggers before too but here I’m sharing a list which is much different from those existing ones. Here, I have taken into consideration a number of factors – importance, generality, usefulness, easy to use, functionality, etc. Besides, maybe this list is the first list of wordpress plugins which will all work with wordpress 2.7. So, if you are using wordpress 2.7, you can install these plugins with ease. Continue Reading »

How to Install many wordpress plugins at once using plugin central!

December 17th, 2008By WaikhomWeb Development,Wordpress Plugins

There are many wordpress plugins out there which you might be interested in. But installing them all might be a big problem – download and then upload and then activate. Today, I’m here to share a technique which will allow you to install all such wordpress plugins at once. Using the plugin central plugin, you can install many wordpress plugins in one simple step provided you know the plugin name or plugin url. And I’m going to teach you how to do that. But first of all you need to install the plugin – Plugin central and activate it (If you don’t know how to install a wordpress plugin, see how to install a wordpress plugin!). Once you have installed this plugin, you are ready to install the many plugins in a few simple steps: Continue Reading »

Top proxy keywords with low competition

December 10th, 2008By WaikhomWeb Development

Making money online with proxy sites is easier if you have a good keyword(s) for which you can optimize your site. The most important reason you should optimize your site for search engines is because search engine traffic is much better than traffic from other sites. Your ads will be clicked more and you will earn more. But if you are running a proxy script and not a proxy related site (e.g. Proxy list, proxy server list etc.), then I recommend not to go for SEO. Because proxies get blocked with time and one day, yours will be too. That day, you will have to start with a new domain but all the efforts you put in your old domain in SEO will be wasted. Now, if you are running a site which gives information about proxies, then the best thing to do is optimize your site with one or more keywords. Continue Reading »

Recent Photos

DSC04900DSC00584DSC00583DSC00580DSC04898DSC00492DSC00339DSC04828