42.3k views
2 votes
How to locate hidden elements in selenium

1 Answer

4 votes

Final answer:

To locate hidden elements in Selenium, you can use the findElement or findElements method of the WebDriver class with appropriate locators.

Step-by-step explanation:

In Selenium, to locate hidden elements, you can use the findElement or findElements method of the WebDriver class. By using the appropriate locators, such as id, name, class name, css selector, xpath, or other supported methods, you can search for hidden elements on a web page.

For example, if you want to locate a hidden element with its id, you can use the following code:

WebElement element = driver.findElement(By.id("elementId"));

If the hidden element has a specific attribute or class name, you can use those as locators as well.

We use JavaScript Executor, tweaking the display:none; for the style attribute to visibility:visible; so that we can make the hidden element visible to the Selenium script. We can change the display:none value of the style attribute to visibility:visible at run time while running the tests.

User Salvi Pascual
by
7.7k points