0

I am trying to create a test to select this button

enter image description here

<button type="submit" class="btn btn--stretch btn--primary btn--green t-auth__login--btn">
                Create my account</button>

the code that I used is this, but it doesn't work

driver.findElement(By.className("btn btn--stretch btn--primary btn--green t-auth__login--btn")).click();

Can somebody tell me the correct way to code this test?

If it is any help, the webpage in question is https://www.dunnesstores.com/customer/login

DebanjanB
  • 118,661
  • 30
  • 168
  • 217

1 Answers1

1

To click() on the element you can use either of the following Locator Strategies:

  • cssSelector:

    driver.findElement(By.cssSelector("button.btn.btn--stretch.btn--primary.btn--green.t-auth__login--btn")).click();
    
  • xpath:

    driver.findElement(By.xpath("//button[@class='btn btn--stretch btn--primary btn--green t-auth__login--btn' and contains(., 'Create my account')]")).click();
    

Ideally to click() on the element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.btn.btn--stretch.btn--primary.btn--green.t-auth__login--btn"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='btn btn--stretch btn--primary btn--green t-auth__login--btn' and contains(., 'Create my account')]"))).click();
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217