How to find button element with webdriver?

Just check for a single dialog-confirm class:

driver.findElement(By.className("dialog-confirm")).click();

Or, use a CSS Selector:

driver.findElement(By.cssSelector("button.dialog-confirm")).click()

Other ways using cssSelector:

  1. Use full attribute i.e.:

    driver.findElement(By.cssSelector("button[class='btn dialog-confirm btn-primary']"))

  2. Use part of attribute i.e.:

     driver.findElement(By.cssSelector("button[class*='dialog-confirm']"))
    

Added to alecxe and master slave's answer. It would be more specific if it is clicked by the button text, which is also easier to understand. Find the snippet for button click with xpath below.

driver.findElement(By.xpath("//button[text()='Confirm']")).click();
driver.findElement(By.xpath("//button[text()='Cancel']")).click();