Search code examples
javaseleniumtestingautomation

Automating a button click issue


I'm having some trouble with automating a button test. How can I automate a test with Java&Selenium to auto-click this following button?

<button class="btn btn-default primary-bg btn-lg">Submit</button>

I tried this:

driver.findElement(By.xpath("//button[@class= .btn btn-default primary-bg btn-lg']")).click();

What am I doing wrong? What other solutions are there?


Solution

  • Try to add ' after class=

         driver.findElement(By.xpath("//button[@class=' .btn btn-default primary-bg btn-lg']")).click();
    

    Or maybe

         driver.findElement(By.xpath("//button[@class='btn btn-default primary-bg btn-lg']")).click();