Wednesday, March 9, 2016

Element is not clickable at point



I was facing the same issue while im on my project and i was stucked at the same issue for more than 6 hours

I was with selenium on c#

My original issue was :
I have bold the most important area. 

Result Message:
Test method FocusTest.TestPropertyOnaPage.TestPropertyOnaPage.ValidateCloseButton threw exception: 
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: unknown error: Element is not clickable at point (514, 158). Other element would receive the click: <div class="row">...</div>
  (Session info: chrome=48.0.2564.109)
  (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.3 x86_64)
Result StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebElement.Click()
 --- End of inner exception stack trace ---
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at OpenQA.Selenium.Support.PageObjects.WebDriverObjectProxy.InvokeMethod(IMethodCallMessage msg, Object representedValue)
   at OpenQA.Selenium.Support.PageObjects.WebElementProxy.Invoke(IMessage msg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at OpenQA.Selenium.IWebElement.Click()
   at FocusTest.TestPropertyOnaPage.TestPropertyOnaPage.Clickbackbutton() in e:\Focus\FocusTest\FocusTest\TestPropertyOnaPage\TestPropertyOnaPage.cs:line 82
   at FocusTest.TestPropertyOnaPage.TestPropertyOnaPage.ValidateCloseButton() in e:\Focus\FocusTest\FocusTest\TestPropertyOnaPage\TestPropertyOnaPage.cs:line 111




Then after doing some various fixes i got the same issue with a different error message.

Result Message:
Test method FocusTest.TestPropertyOnaPage.TestPropertyOnaPage.ValidateCloseButton threw exception: 
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> OpenQA.Selenium.ElementNotVisibleException: element not visible
  (Session info: chrome=48.0.2564.109)
  (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.3 x86_64)
Result StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebElement.SendKeys(String text)
 --- End of inner exception stack trace ---
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at OpenQA.Selenium.Support.PageObjects.WebDriverObjectProxy.InvokeMethod(IMethodCallMessage msg, Object representedValue)
   at OpenQA.Selenium.Support.PageObjects.WebElementProxy.Invoke(IMessage msg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at OpenQA.Selenium.IWebElement.SendKeys(String text)
   at FocusTest.TestPropertyOnaPage.TestPropertyOnaPage.ReturnTitleTextForBackButtonValidation(String SearchTxt) in e:\Focus\FocusTest\FocusTest\TestPropertyOnaPage\TestPropertyOnaPage.cs:line 72
   at FocusTest.TestPropertyOnaPage.TestPropertyOnaPage.ValidateCloseButton() in e:\Focus\FocusTest\FocusTest\TestPropertyOnaPage\TestPropertyOnaPage.cs:line 127



Any way my original issue was on my web page there is a small close button, when i try to click on the close button thru the code it gave me the 1st error message.
But the same code working fine in firefox.

So i tryid with :
driver.manage().window().maximize();
Updating chrome driver
IWebElement elementToClick = <code to get element>;

// Scroll the browser to the element's Y position
(driver as IJavaScriptExecutor).ExecuteScript(string.Format("window.scrollTo(0, {0});",
elementToClick.Location.Y));

// Click the element
elementToClick.Click();
// Find an element and define it
WebElement elementToClick = driver.findElement(By.xpath("some xpath"));
// Scroll the browser to the element's Y position
((JavascriptExecutor) driver).executeScript("window.scrollTo(0,"+elementToClick.getLocation().y+")");
// Click the element
elementToClick.click();
IWebDriver driver = new ChromeDriver(@"d:\selenium");
            driver.Navigate().GoToUrl("http://...");

            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            IWebElement btn = wait.Until<IWebElement>((d) =>
            {
                return d.FindElement(By.Id("button-xxxx-btnInnerEl"));
            });
            Thread.Sleep(5000); //it works after added this sleep statement
            btn.Click();

Unfortunately nothing is work for me.No damn luck

Finaly i use this code.

            Elements.PropertyOnaPageElm elm = new Elements.PropertyOnaPageElm();
            Actions actions = new Actions(Setup.SetupSeleniumWebDriver.driver);
            actions.MoveToElement(elm.BackButton).Click().Perform();

and it works supper fine.