-1

enter image description here

I want to get validation message value in Eclipse using Selenium WebDriver.

I have written code below but it display syntax error:

WebElement errormsgfornewpass = driver.findElement(By.xpath("//span[@class='field-validation-error']//span[@class='NewPassword']"));
String errnewmsg = errormsgfornewpass.getText();
System.out.println("errormsg->"+errnewmsg);
  • While it looks like you determined you were using the wrong locators, for future reference, saying "it display syntax error" is not very useful for those who are trying to answer questions. If you're getting an error, share what the exact error is. – ernie Feb 19 '17 at 0:19
1
//Getting the WebElement.
WebElement errormsgforoldpass = driver.findElement(By.xpath("//span[@class='field-validation-error']//span[@for='OldPassword']"));

//Getting the text of the webelement.    
String erroldmsg = errormsgforoldpass.getText();

//Printing the text of the webelement.
System.out.println("errormsg->"+erroldmsg);
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.