Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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'm trying to extract a certain message from my app. The text starts up as visible and then changes to style= "visibility: hidden" the visibility period is rather short, and I was wondering how can I extract this text using Selenium after it changes status to hidden.

I'm using a simple element.getText() command to get this text, which works when it's visible but returns nothing when hidden.

share|improve this question
Thanks a lot . I used in Selenium Webdriver java for getting CheckBox text. My code which worked fine for me: String checkBoxLabel= (String)((JavascriptExecutor)Browser.driver) .executeScript("return arguments[0].innerHTML",checkLabelTextElement); System.out.println("CheckText is"+checkBoxLabel); – user9391 Nov 29 '14 at 8:53
up vote 7 down vote accepted

I had the same problem and actually dislike this "feature" in Selenium. In my C# abstraction layer I replaced getText with this:

return ((IJavaScriptExecutor)webDriverInstance).ExecuteScript("return arguments[0].innerHTML", elementInstance).ToString();

share|improve this answer
Thanks a lot for the quick answer, I will give this a try. I'm still kind of new to java and selenium so might take me some time to report if it worked – Gil_G Apr 19 '12 at 16:18
Thanks a lot, it worked perfectly, instead of my element.getText(); I used 'JavascriptExecutor js = (JavascriptExecutor) driver; (js.executeScript("return arguments[0].innerHTML", element)); and I get my value regardless of visibility status. – Gil_G Apr 20 '12 at 5:46
@Gil_G You should accept the answer – SteveCZ Apr 20 '12 at 6:50
Oh, yeah i didn't notice that.....Done! – Gil_G Apr 20 '12 at 20:59
it extract tag and attribute too.. not only text – JackTurky Jul 28 '12 at 22:19

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.