0

I am struggling to click a continue button in my selenium. I try to use .click() but it states element is not clickable. I've tried waiting for the element to be visible before hand and even tried following the solutions in this article Debugging "Element is not clickable at point" error but no luck.

Does any body know why this is being an issue? I am testing this in chrome.

<div class="basket-summary__continue"><button data-href="" data-component="Booking/Navigation/ContinueButton" class="bttn bttn--primary bttn--full-width">
    Continue
</button></div>

 public void ClickContinue()
    {
        Thread.Sleep(10000);
       _driver.FindElement(By.ClassName("basket-summary__continue")).FindElement(By.XPath("/html/body/div[2]/div[4]/div/div[2]/div[1]/div[1]/div[2]/div[2]/div[3]/button")).Click();
    }

P.S I don't really want to use Thread.Sleep but just using it for now to create a wait.

Thank

BruceyBandit
  • 3,978
  • 19
  • 72
  • 144
  • can you give us the full stack trace of the exception? – Murthi Sep 15 '17 at 09:44
  • 1
    _driver.FindElement(By.Xpath(//button[@class='bttn bttn--primary bttn--full-width']")).click(); – iamsankalp89 Sep 15 '17 at 09:47
  • That xpath looks a prime candidate for the issue. Just for now I would place a unique ID on the – bilpor Sep 15 '17 at 09:49
  • @Murthi: An exception of type 'System.InvalidOperationException' occurred in WebDriver.dll but was not handled in user code Additional information: unknown error: Element is not clickable at point (1278, 4160) – BruceyBandit Sep 15 '17 at 10:20
  • when you are manually looking at it on the page, do you have to scroll down to click it? – Dazed Sep 15 '17 at 14:31

2 Answers2

0

You can wait for element to be clickable -- i.e. is visible and enabled -- using ExpectedConditions class.

Please, check the following doc: https://seleniumhq.github.io/selenium/docs/api/dotnet/html/M_OpenQA_Selenium_Support_UI_ExpectedConditions_ElementToBeClickable.htm

0
@FindBy(xpath = "//div[@class='basket-summary__continue']/button")
private WebElement button;

or

By buttonBy = By.xpath("//div[@class='basket-summary__continue']/button");

Then create an Explicit wait for Element clickable before clicking the button.

/***
 * An expectation for checking an element is visible and enabled such that you can click it.
 * @param locator - used to find the element
 * @param timeout
 * @return the WebElement once it is located and clickable (visible and enabled)
 */
public WebElement elementToBeClickable(By locator, int timeout) {
    try {
        return getWebDriverFluentWait(timeout)
                .until(ExpectedConditions.elementToBeClickable(locator));
    } catch (Exception e) {
        return null;
    }
}

private Wait<WebDriver> getWebDriverFluentWait(int timeout) {
    return new FluentWait<WebDriver>(driver)
            .withTimeout(timeout, TimeUnit.SECONDS)
            .pollingEvery(1, TimeUnit.SECONDS)
            .ignoring(NoSuchElementException.class);
}

Finally, we can perform the function like:

WebElement btnContinue = elementToBeClickable(buttonBy, 10); # wait for element clickable within 10 seconds timeout.
btnContinue.click();

// sorry that I am more on Java but I think we have the same solution for other language.

Tony Bui
  • 815
  • 5
  • 7
  • Hi Tony, sorry i am a little bit of a c# noob, do you first want me to create this first: public void ClickContinue() { _driver.FindElement(By.XPath("//div[@class='basket-summary__continue']/button")); private WebElement button; } – BruceyBandit Sep 15 '17 at 10:46
  • I have updated with a few more code in the answer. Hope it works! – Tony Bui Sep 15 '17 at 10:52