Balaji Mohan
Balaji Mohan

Reputation: 63

Element Click Intercepted Exception

I am unable to perform click operation on Sign-in button in my application.

Below is the HTML code.and u can find the exact button element in last line.

<div class="form-group dl-padding-10">

                        <select class="form-control form-control-solid" name="SelectedRoleID" id="SelectedRoleID" onchange="removeBorderColor()" required="">
                                <option id="default_val" selected="" disabled="" hidden="">Profile </option>
                                    <option value="15">Service Consultant</option>
                                    <option value="11">DLBO Developer</option>
                                    <option value="16">Admin Agent</option>
                                    <option value="17">Team Leader</option>
                                    <option value="18">Manager</option>
                                    <option value="19">CV Mandator</option>
                                    <option value="20">CV Agent</option>
                                    <option value="21">Forensics Agent</option>
                        </select>
                        <div class="dl-align-left" id="show_text" style="color:red">
                            &nbsp;
                        </div>

                    </div>

                    <div class="circle1-mask form-group" id="FingerprintContent" style="height:140px;z-index:2; background-image: none;">
                        <img src="Assets/img/fingerprint4.gif" id="fingerprint-img" data-status="active" style="height:140px; width:100px;" onclick="DeviceScript.scanFingerPrint(event)">
                    </div>
                        <div class="form-group dl-padding-10">
                            <button type="submit" id="register-btn" class="btn btn-block dl-button-primary dl-no-margin">Sign In (For Testing Purpose Only)</button>
                        </div>


                </div>
            </div>
</form>    </div>
</div>

Kindly help me with the suitable xpath to perform click operation on the sign-in button.

Also find the image of code tried.Code

Xpath=”//button[contains(text(), 'Sign In (For Testing Purpose Only)')]”
(Or)

IWebElement Signin = driver.FindElement(By.Id("register-btn"));
            Signin.Click();
(Or)

IWebElement Signinbutton = driver.FindElement(By.XPath("//button[contains(text(), 'Sign In (For Testing Purpose Only)')]"));


            Actions action = new Actions(driver);
            
            action.MoveToElement(Signinbutton).Click().Perform();
The error which i get:
OpenQA.Selenium.ElementClickInterceptedException : element click intercepted: Element <button type="submit" id="register-btn" class="btn btn-block dl-button-primary dl-no-margin">...</button> is not clickable at point (758, 646). Other element would receive the click: <div class="footer navbar-fixed-bottom">...</div>

Upvotes: 0

Views: 6959

Answers (3)

Toothless Rider
Toothless Rider

Reputation: 51

The exception you are getting is because the button you are trying to click is behind this element <div class="footer navbar-fixed-bottom">...</div> Which seems to be the footer of your page.

You can try any of the following steps to solve the issue

  1. Scroll to any element below the sign-in button(If any). You can use the below code for that:

    protected boolean scrollToElement(WebElement element) throws NoSuchElementException, StaleElementReferenceException { try { jsExecutor.executeScript("arguments[0].scrollIntoView(true);", element); return true; } catch (NoSuchElementException e) { logError("Element Not found exception when scrolling to element (JavaScript)", e); throw e; } catch (StaleElementReferenceException e) { logError("Stale element exeption when scrolling to element (JavaScript)", e); throw e; } }

    1. Close the footer if it is for accept cookies or something similar, or you can also apply Custom CSS to that element to hide it and then try to click the element.

    String css= "display:none !important;" protected void addCustomCSS(WebElement webElement, String css) { registerCall(new Object() { }.getClass().getEnclosingMethod().getName()); try { String style = (String) jsExecutor.executeScript("arguments[0].getAttribute('style')", webElement); jsExecutor.executeScript("arguments[0].setAttribute('style', " + css + ")", webElement); stylesQueue.add(style); } catch (Exception e) { e.printStackTrace(); } }

Upvotes: 0

SeleniumUser
SeleniumUser

Reputation: 4177

Try with javascript:

IWebElement Signinbutton = driver.FindElement(By.XPath("//button[contains(text(), 'Sign In (For Testing Purpose Only)')]"));
IJavaScriptExecutor javascriptExecutor = (IJavaScriptExecutor)driver;
executor.ExecuteScript("arguments[0].click();", Signinbutton );

Upvotes: 2

Dazed
Dazed

Reputation: 1551

Looks like you are missing some html since the error references a footer.

Not a fan of thread sleeps but try one and see if the thread sleep allows the page to load. I am wondering if your page is still loading and trying to click. If the sleep works, I would remove that and do a move to element or try a java click.

Thread.Sleep(1000);
driver.FindElement(By.XPath("//button[contains(text(), 'Sign In')]")).Click();
driver.FindElement(By.Id("register-btn")).Click();

Upvotes: 0

Related Questions