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.
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
There is also the long option which uses selenium's element displayed functionality.
from selenium import webdriver b = webdriver.Chome() b.get('https://google.com') els = b.find_elements_by_css_selector('*') hidden_els = [el for el in els if not el.is_displayed()] print(hidden_els) b.quit()