Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am automating a site in which there is a section to create forums. Every time I create a forum it displays message as forums created and hides after 1 section. I have to check the displayed message, But many times it throws exception as "Element is not usable"

private WebElementFacade forums;

private WebElementFacade message;;
 assertThat(message.getText(),equals("expected"); //here the element message throws "Element is not usable exception" as it hides with in two seconds.. 

public String getMessage() {
    String messagetxt = "";
    try {
        if (Message.isDisplayed()) {
            messagetxt = Message.getText();
        } else {
            messagetext = ((JavascriptExecutor) getDriver()).executeScript(
                    "return arguments[0].innerHTML", Message).toString();
    } catch(NoSuchElementException ne) {"status message not displayed..... checking from the page source"+ nsee);
    return messagetxt;

How can I find the element or at least handle the exception

share|improve this question
as per the reply by sam woods i have made some changes in the code and my new code is available above, here I have handled exception. But the else block is not executed, Is there any way to execute the else block once the exception occurs?? – Ajmal Feb 7 '14 at 10:44

You may or may not be able to interact with the element in time, depending on the speed of your computer and your browser.

There are selectors that are faster or slower. Typically, selecting by ID is the fastest, followed by selecting by Name, and in most browsers, CSS selectors are the next fastest. Since you are already selecting by ID, there's probably not a whole lot you can do to make it find the element faster.

If you are just trying to validate the text of the message, you can use the javascript executor to execute some javascript to get back the text of the element even if it is hidden, but you won't be able to validate that the message was actually displayed - only that the text of the message is what you expect.

Not sure exactly what language you're using, but in Java you could write something like this:

catch(Exception e){
  //Log unable to verify message displayed
String messageText = ((JavascriptExecutor) driver).executeScript("return arguments[0].innerHTML", message);
share|improve this answer

Here you can find a lot of help. There are lot of people who use selenium/webdriver.

share|improve this answer
Why I get -1? I show him/here where he can find help. Did I do something wrong? – SayusiAndo Feb 6 '14 at 17:40
Probably because you didn't answer the question you just linked to a user group with no context. – Ardesco Feb 7 '14 at 14:39
Probably. Tahnks for the answer! :) – SayusiAndo Feb 7 '14 at 14:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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