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

DebanjanB
  • 118,661
  • 30
  • 168
  • 217

4 Answers4

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();
Subburaj
  • 2,176
  • 2
  • 11
  • 32
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();
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
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.

  • ref: https://stackoverflow.com/questions/40386805/webdriver-can-login-in-chrome-not-in-firefox-unable-to-find-owning-document – Ajaya Tiwari Aug 14 '19 at 06:22
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.