Resolving – Element is not clickable at point

Here is a simple solution to resolve the Element is not clickable at point issue with ChromeDriver in Webdriver.
Here is the function I have written to detect the browser and then pause for .5 sec before executing the next command.

public bool CheckElementPresent(string Xpath)
{
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
string ibrowser = (string)js.ExecuteScript("return " + "navigator.userAgent");
if (ibrowser.Contains("Chrome"))
{
Thread.Sleep(500);
}
bool present = false;
for (int second = 0; ; second++)
{
if (second >= 10)
{
break;
}
if (IsElementPresent(Xpath))
{
present = true;
break;
}
Thread.Sleep(1000);
}
return present;
}

Here is the code where I have used the function:
//click view more link
CheckElementPresent(ViewmoreCategory_lnk);
Click(ViewmoreCategory_lnk);
//click add another keywords link
CheckElementPresent(AddAnotherHyperLink);
Click(AddAnotherHyperLink);

I hope this will be useful for you.

Using Selenium in a Ajax web application

On an Ajax web application or Ajax feature on web page small sections of the page will update and often the entire webpage will not load. It’s necessary to wait until this ajax process is completed before interacting with sections of the page where content or controls are yet to be rendered.

The Ajax application architecture

If you are using Selenium a simple sleep or wait is a bad idea. The Ajax calls do not the same time to perform an operation every time. If the wait period is too short, you’ll have random test failures since a control you want to interact with is missing. If the period is too long, your tests take too long since you end up waiting, very often, far longer than you need to.

The best approach is to use the selenium waitForElementPresent(locator) command.
for (int second = 0;; second++)
{
if (second >= 60) Assert.Fail("timeout");
try
{
if (selenium.IsElementPresent("//div[@id='locator']")) break;
}
catch (Exception)
{}
Thread.Sleep(1000);
}

The Selenium Command waitForElementPresent waits till a particular element shows up on the page. The other option is waitForCondition(locator) command, which takes a javascript function and waits till it evaluates as true. See here.
selenium.WaitForCondition(“//div[@id=’locator’]”, “”);

You can also use the selenium.browserbot.getCurrentWindow() selenium.browserbot.getUserWindow().$.active == 0. The browser tells us how many active connections to the server are present. Then we sit and wait for that number to become 0. At this point we know that all Ajax requests went through and done, and we can move on in the test.

Here is the code in C# using the selenium.browserbot.getUserWindow().$.active == 0 command with selenium.WaitForCondition command.

selenium.WaitForCondition("selenium.browserbot.getCurrentWindow().jQuery.active == 0", "5000");
selenium.WaitForCondition("selenium.browserbot.getCurrentWindow().$.active == 0", "5000");

I have also used the selenium.WaitForCondition(“selenium.browserbot.getCurrentWindow().jQuery.ajax.active == 0”, “15000”); but the issue is that I keep getting timeout issue. I am yet to resolve the issue. I will update once I get the issue resolved.

If you found this solution helpful or have something extra to add, feel free to share it here by commenting below.