The main differences between Selenium IDE and Selenium WebDriver

Websites had become one of the dominant technologies which revolutionized the entire world for several years. Eventually, the web browser too had become one of the significant platforms to browse through millions of websites across the globe. Testing such websites and applications is a challenging task and Selenium had become one of the demanding tools for testing the User Interface. Here, in this article, we’ll discuss the core differences between the Selenium IDE (Integrated Development Environment) and Selenium WebDriver.
While not the only browser automation tools around, Selenium is without doubt one of the most popular. We must immediately clarify the difference between Selenium IDE and Selenium WebDriver.
Selenium IDE
Selenium IDE is a Firefox add-on with which you can record your own navigation for a later playback. Writing code is not required; the user interface is flexible enough to allow you to create simple test cases.
Selenium WebDriver
Selenium WebDriver is essentially a library from which we can drive the browser by code. As usual, an example can be much more useful than a thousand words.
Let us consider the following Selenium WebDriver code which is the lines of code for Console application to initiate Firefox web browser with Google home page.
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
//...
static void Main(string[] args)
{
using (IWebDriver driver = new FirefoxDriver())
{
driver.Navigate().GoToUrl("http://www.google.com");
driver.Quit();
}
}
Let us examine how we can perform a Google search with the help of the above code.
using (IWebDriver driver = new FirefoxDriver())
{
driver.Navigate().GoToUrl("http://www.google.com");
IWebElement textbox = driver.FindElement(By.Id("lst-ib"));
textbox.SendKeys("Selenium WebDriver c#");
textbox.SendKeys(Keys.Enter);
driver.Quit();
}
As you can see it’s very easy to find specific html items inside the page. In this case, we used the By.Id() method, but there are many more. Now, suppose you want to extract the links from the first page of search results, we can make use of the following code modified from the above.
using (IWebDriver driver = new FirefoxDriver())
{
driver.Navigate().GoToUrl("http://www.google.com");
IWebElement textbox = driver.FindElement(By.Id("lst-ib"));
textbox.SendKeys("Selenium WebDriver c#");
textbox.SendKeys(Keys.Enter);
var links = driver.FindElements(By.CssSelector("h3.r > a"));
foreach (var link in links)
{
Console.WriteLine(link.Text);
}
driver.Quit();
}
Here, unfortunately, running the above lines of code will not give any result (in most cases). This is mainly because of the fact that Selenium does not know that it has to wait for the results page to be loaded. After the instruction textbox.SendKeys(Keys.Enter), the next line is immediately performed and then the CSS selector finds nothing. Instead, when we use methods of Navigate(), Selenium knows that we are loading a new page and then before continuing, it waits the page to be fully loaded. You can try yourself to test this behaviour: instead of loading the google home page, try to load the result page:
Thus, to conclude this blog, it could be stated that by exploring the various methods of Selenium WebDriver, and with a little imagination, beautiful results can be explored.
Stay Connected to Indian America
Get the latest community stories, local events, entertainment and lifestyle updates delivered to your inbox.