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 am trying to create a Selenium Web driver java code where I can find all the hidden objects on the webpage and can be accessed. I want the count of all those hidden objects. Which property I can use in the code which can identify hidden objects because when I thought of using get Element by property so that i can search for objects with hidden property, it was not there. Is there anything i am missing here. Is it really possible ? Or do we need to know the id of the element to be found ? Any Inputs will be useful.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

What kind of hidden objects are you looking for? If it's any HTML tags with the attribute display: none; try using

List<WebElement> elements = driver.findElements(By.cssSelector("[display=none]"));
int count = elements.size();

This uses CSS matching to find all HTML elements with the display attribute equal to none. Then get the size of the returned list with the size() method.

share|improve this answer
    
Thanks for that and my aim here is to find all the objects that are in the web page but are hidden, could be Html elements or not. Is it feasible ? –  khappi Sep 19 '13 at 5:58
    
From my experience hidden webpage elements would have either display:none or visibility:hidden. –  Francis Sep 19 '13 at 6:02
1  
Or they could be simply hidden behind an overlay, or with ajax it is sometimes common to actually remove unused elements from the dom and re-add them when needed. As Francis noted - looking for the styles display=none and visibility:hidden will find you all of the elements that are hidden via CSS and styling. –  Sam Woods Sep 19 '13 at 15:18
    
Hey Francis. I tried running the code you suggested both ways but i am still getting the count as 0. is there anything which needs to be rectified. I tried testing it on multiple websites but its not getting me any output. Please help. –  khappi Sep 20 '13 at 18:16
    
Try replacing display=none with visibility=hidden. If the count is still 0 then the elements aren't hidden by CSS but might be either under an overlay or removed from the DOM as Sam noted. –  Francis Sep 20 '13 at 19:23
show 3 more comments

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.