Please help me to get the Error message.

<div id="divDraftErrorMessages" data-ng-show="showDraftErrorMessage()" class="alert alert-danger">
  <div data-ng-repeat="message in draftErrorMessages" class="ng-binding ng-scope">
    <img src="../../Images/alert.gif" alt="Error Message">
 Invalid Keyword

I tried with below code but message is printed. Observed failure.

String message = driver.findElement(By.className("ng-binding ng-scope")).getText();

I am struggling as error message is preceded with image. Please help.

The error I get is

org.openqa.selenium.InvalidSelectorException: invalid selector: Compound class names not permitted

2 Answers 2


The problem is that Selenium only allows a single class name, so you can't use "ng-binding ng-scope" as your class selector. You can only use one of the two classes.

I'd suggest starting by getting the outer div by ID since you have an ID to work with. If the inner div is the only div that will display, you can then use findElement(By.tagName("div")).getText(); to retrieve the text.

If that gives you the image HTML as well as the text (it shouldn't), you can use a simple substring function to keep only the text after the >.

So your code should do something like:

outerdiv = driver.findElement(By.id("divDraftErrorMessages"));
message = outerdiv.findElement(By.tagName("div")).getText();

ng-binding and ng-scope are 2 different classes. Compound classes are not supported by class selector in selenium. You can use the xpath if want to access the element based on more then one class like below :-

String message = driver.findElement(By.xpath("//div[@class='ng-binding ng-scope']")).getText();

or can be CSS Selector as :

String message = driver.findElement(By.cssSelector("div.ng-binding.ng-scope")).getText();

Your Answer

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

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