0

Unable to click on Save button using By.className while className available in webpage code for button available

<div class="popupFooter">
<div align="center">
<input id="Preview-btn" class="btn-primary previewDetaile" type="button" value="Preview">
<input class="btn-primary validateProfile" type="button" value="Save">
<input id="clear" class="btn-primary" type="button" value="Cancel">
</div></div>

Selenium Code

 driver.findElement(By.className("btn-primary validateProfile")).click();

Problem: Unable to click on Save button

Ajinkya
  • 22,324
  • 33
  • 110
  • 161

2 Answers2

5

Your problem is that you search for multiple classnames which does not work with By.className. Just try

driver.findElement(By.className("validateProfile")).click();

instead. For selecting elements by multiple classnames you can find a solution here.

Community
  • 1
  • 1
Sebastian
  • 5,721
  • 3
  • 43
  • 69
2

It's very easy with a CSS selector:

driver.findElement(
  By.cssSelector(".btn-primary.validateProfile")
).click();

For a full reference:

http://www.w3schools.com/cssref/css_selectors.asp

As @Sebastian pointed out, it's probably due to the fact that By.className accepts only one class name (I think it's not by chance that they didn't name it By.classNames :) )

alb-i986
  • 325
  • 2
  • 14