Take the 2-minute tour ×
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.

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
add comment

1 Answer 1

up vote 6 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
show 1 more comment

Your Answer

 
discard

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.