Search Here!

Sunday, September 2, 2012

WebDriver: Click Techniques


There are number of techniques by which you can interact with web page. As Selenium tool - WebDriver is a very strong tool to interact with various elements on web page but sometimes we stuck in this and not able to understand why it is happening. If we are doing Automation it means, it would work in every condition and every environment. From my experience once time, my code is able to click an element on my local system but same code when running on taking system remote, it won't(we had the same environment on both the systems).

So, I mean there is a lack of interaction of WebDriver with web page when I was running it on remote system yes there was some network speed issue but we already used the ideal waits for elements.

I came to know that there were lots of JavaScript on page where I was generally getting issue due to JavaScript error(s) or due to lazy load of JavaScript on the webpage. Sometimes JavaScript fully loaded on the page sometimes not due to network speed on the remote system. As WebDriver itself is a JavaScript based tool, so could not go beyond that to avoid JavaScript based errors.

So, Following techniques helps you to click element on the page and various other actions too:

ü        If page or pop up’s contains no JavaScript then we can use for click,

WebDriver.FindElement(By.Id("_ctl0_ContentHolderHeader_lbtnSavePrefHeader")).Click();

ü                   ü If page or pop up’s contains some JavaScript’s then we can use for click,

IWebElement isPageLoaded = WebDriver.FindElement(By.Id("ImgPoweredBy"));
isPageLoaded.Click();

ü                  ü If page or pop up’s contains possible more JavaScript and JavaScript’s Errors then we can use for click,

IWebElement menu = WebDriver.FindElement(By.XPath("//table[@id='GridStudent']/tbody/tr/td[2]/span"));
            Actions builder = new Actions(WebDriver);
            builder.Click(menu).Perform();

ü                  ü If page or pop up’s contains highly JavaScript’s and JavaScript’s Errors then we can use,

IWebElement menu = WebDriver.FindElement(By.XPath("//table[@id='GridStudent']/tbody/tr/td[2]/span")); 
((IJavaScriptExecutor)WebDriver).ExecuteScript("$(arguments[0]).click()",menu);

No comments:

Post a Comment