Button not clickable consistently in Selenium Java

not able to click on element in selenium webdriver
element is not getting clicked in selenium
selenium click not working in chrome
how to click on before in selenium
not able to click button in selenium
unable to click on dropdown in selenium webdriver
button not clickable selenium
alternative for click in selenium

I am trying to click a button in selenium java code and it is not clicking all the time. Apparently this is pretty common issue.

I tried below few solutions:

HTML Code :

<button class="btn btn--action btn--border-white btn--my__calculate" style="display: inline-block;">Final Figure</button>

Solution 1:

WebElement btnWorkout = webDriver.findElement(By.cssSelector(".btn--my__calculate"));

        if (btnWorkout.isDisplayed() && btnWorkout.isEnabled()) {
            btnWorkout.click();
        }

Solution 2 :

WebDriverWait wait = new WebDriverWait(webDriver, 10);
        WebElement btnWorkout = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".btn--my__calculate")));
        btnWorkout.click();

Solution 3:

WebElement btnWorkout = webDriver.findElement(By.cssSelector(".btn--my__calculate"));
JavascriptExecutor executor = (JavascriptExecutor) webDriver;
        executor.executeScript("arguments[0].click();", btnWorkout);

None of them worked for me.

Other strange thing is above step passes without an error and button doesn't click as expected

Induce WebDriverWait And Following Xapth. Try following options.

Option1:

WebDriverWait wait = new WebDriverWait(webDriver, 20);      
WebElement btnWorkout=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='btn btn--action btn--border-white btn--my__calculate'][text()='Final Figure']")));
btnWorkout.click();

Option2: Use Action class

WebDriverWait wait = new WebDriverWait(webDriver, 20);      
WebElement btnWorkout=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='btn btn--action btn--border-white btn--my__calculate'][text()='Final Figure']")));
Actions action=new Actions(webDriver);
action.moveToElement(btnWorkout).click().build().perform();

Option3: Use JavaScript Executor

WebDriverWait wait = new WebDriverWait(webDriver, 20);      
WebElement btnWorkout=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='btn btn--action btn--border-white btn--my__calculate'][text()='Final Figure']")));
JavascriptExecutor executor = (JavascriptExecutor) webDriver;
executor.executeScript("arguments[0].click();", btnWorkout);

Button won't click even though I can see it's taking me to the button , First Check the button is able to be clickable at the moment of your try. Sometimes the page load is very long it's not clickable at the moment. Use the below code  I am trying to click a button in selenium java code and it is not clicking all the time. Apparently this is pretty common issue. Button not clickable consistently

Curious that the executeScript() option didn't work for you. Keep using your WebDriverWait from option 2, but instead of the click() method, try using Action Chains. I'm not sure how to write this in Java, but it'll be something like this:

Actions action = new Actions(driver);
action.move_to_element(btnWorkout).click(btnWorkout).perform();

Selenium Click functionality does not work consistently · Issue , Selenium Click functionality does not work consistently #4075 Click() / Actions Class/ Click using JS/ Press Enter button on element but none is working all the time. so no other Java script or jQuery actions are involved. We should always get exception, because this button never becomes clickable. But I was expecting to get that exception after 5 seconds because that is the timeout provided. Web page in test script may not be the best example, but this is reproducible on other pages with disabled buttons.

Maybe you have another hidden element with same CSS (class). You can try capture the element by linkText or partialLinkText like this:

WebElement btnWorkout = webDriver.findElement(By.linkText("Final Figure"));

How to Fix Selenium's "Element Is Not Clickable at Point", The question is, “why is the element not clickable if the element is found?” The reason for this being common in the Chrome browser is because the Chrome driver always clicks in the middle of the element. that the “submit” button is enabled only after the data validation is done. driver = webdriver. Click button is not working, that is the button is not clickable. If that is the case then no automated or manual process and click the button. If you can use any keys like ENTER to do the step, you can do the same with Selenium.

How do we click in Selenium when the click button is not working , (which not worked in your case) [code]WebElement element = driver.findElement​(By Locators) How do we click in Selenium when the click button is not working​, and JavaScript is also not working? atdcVk with Selenium. a java example. Click operation should always work when no exception is thrown. Actual Behavior - Click action works something and sometime it does not. It shows the element is actually being clicked, as for link and buttons we can see dotted border around the object. However the action on that click is not triggered.

Click command in selenium webdriver does not work, Currently, I'm working on finding out why clicking on a button does not work with web driver while it had previously worked in selenium IDE. The reason for the element is not clickable at point(x,y) exception. Some of my observation was. It mostly happens in Chrome so if you are mostly working with Firefox or IE then you will not be getting this exception. Chrome does not calculate the exact location of element; Chrome always click in the middle of Element.

Clicking issues - ChromeDriver, ChromeDriver can't click an element - always throws 'Element is not clickable' error. ChromeDriver clicking works by simulating a mouse click in the middle of  That is the reason Selenium Click was not able to click on element. Search button is overlapped by an auto suggestion option. Exception details also shows that which element will get click instead of search button. That is the reason neither wait worked nor wait for clickable. JavaScript works at DOM level directly so it was able to click.

Comments
  • provide HTML code of button
  • have you tried Thread.sleep? I mean just to confirm that is something that is taking time to load. On some cases had to use this "dirty" solution. Another that sometimes work is "driverWait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("
  • Try with clicking twice or try actions click. I prefer this workaround whenever I face this kinda issue.
  • @Somber Added HTML code to the question
  • @Breaks Software Is there difference behavior when come to Thread.sleep(); when running IDE and command-line. Because when apply Thread.sleep() it works most of the time in IDE but not command-line.
  • I tried all above options and still failing intermittently. Apparently javascript is better. The other thing I noticed was, when it's failing cannot even click the button manually in the opened browser.