Category: <span>Blog</span>

Smart click (part 1)

When using the Selenium Webdriver tool for testing web-based applications, I faced a problem: sometimes the common Click() method does not work for specific elements. Or, for example, it may work fine in the FF browser and fails to click in Internet Explorer. After a little investigation, I noticed that instead of the Click() method I can use methods from the Actions class, or I can click elements with JavaScript. But I also discovered that I have to use one action for FF and another for IE – often an action worked with one browser but failed with the other. I …

Smart click (part 2)

Here is the explanation how you can implement your own Click() method and what is behind the scenes. I will describe the method using a pure IWebElement instance. To be able to invoke the method out of an IWebElement, it should be declared as an IWebElement interface extension method. The method will have a couple of overridden versions for different sets of input parameters. Ok, let’s start. First of all let’s define what the method should do: It checks if the clicking action may be done It checks if all the necessary conditions for successful clicking are met (for example, some …

Smart click (part 3)

In this part I decided to show some examples of using the SmartClick() method just to make the way it works easier to understand. Example 1 – the simplest. In 99% of cases you can use it without any parameters just like an IWebElement interface extension method: public void GoogleSearch() { IWebDriver driver = new FirefoxDriver(); driver.Navigate().GoToUrl(“http://www.google.com”); IWebElement query, btnSearch; WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5)); query = driver.FindElement(By.Name(“q”)); query.Clear(); query.SendKeys(“selenium”); btnSearch = driver.FindElement(By.Name(“btnG”)); btnSearch.SmartClick(); wait.Until((d) => { return d.Title.StartsWith(“selenium”); }); Assert.AreEqual(“selenium – Google Search”, driver.Title); } In this case SmartClick works like native method Click() with some additional functionalities, such …