0

enter image description here

Click button via class because it has no ID . Or via value?

tried className , cssSelector , partialLinkText and LinkText but sadly did not work clicking the save button

System.out.println("Succesful in Saving Product ");
WebElement save = driver.findElement(By.className("bttn-positive save-button"));
save.click();

Should be able to click save button

3
  • either element not interactable or stalemate error pops out Commented Aug 14, 2019 at 6:15
  • can you please post the html snippet? Commented Aug 14, 2019 at 6:19
  • The locator you are using is not valid. Post the html and error message. Commented Aug 14, 2019 at 6:49

4 Answers 4

1

we can not use the multiple class name in the className locator. So, you can use the XPath locator with the multiple class name as below (//input[@class='bttn-positive save-button'])

Code:

System.out.println("Succesful in Saving Product ");
WebElement save = driver.findElement(By.xpath("//input[@class='bttn-positive save-button']"));
save.click();
Sign up to request clarification or add additional context in comments.

Comments

1

You can't pass multiple classnames while using driver.findElement(By.className("bttn-positive save-button")) and doing so you will face Invalid selector: Compound class names not permitted error.

To click() on the green button with text as Save you have 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("input.bttn-positive[value^='Save'][type='button']"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[contains(@class, 'bttn-positive') and starts-with(@value, 'Save')][@type='button']"))).click();
    

Comments

0

Try save.submit();

Submit buttons are used to submit the entire form to the server. We can either use the click () method on the web element like a normal button as we have done above or use the submit () method on any web element in the form or on the submit button itself.

1 Comment

0

In this case "save.click()" will be work, but some time to save any product on any app like eCommerce or Banking domain it will not working properly & one more important think click () cause a new page to load, this method will attempt to load the page . So better to use "save.submit()" if the current elements is form Or with in the form the this will be submitted. As up ur requirements submit () one is the better option.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.