how to handle hidden elements in selenium webdriver code example

Example 1: how to handle hidden elements in selenium webdriver

JavascriptExecutor js=(JavascriptExecutor)driver;
js.executeScript("document.getElementsByClassName(ElementLocator).click();");

Example 2: how to handle hidden elements in selenium webdriver

When the web element is hidden on the page we get
ElementNotVisibleException.
For handling hidden elements we can use:
1- Actions class: To perform the click on the hidden element we
can perform the action. First we should make that button visible
with some actions, like mouse over event, click another element,
etc. Then we perform the click, once visible.
public void hoverOverElementAndClick(WebElement element) {
Actions action = new Actions(driver);
action.moveToElement(element).perform();
element.click(); }

2- JavascriptExecuter: Selenium allows to execute JavaScript
within the context of an element, so we could write JavaScript to
perform the click event, even if it is hidden.
public void jsClick(WebElement element) {
((JavascriptExecutor) this.driver).executeScript("return
arguments[0].click();", element); }

3- Wait method Until Expected Conditions Are Met: We can
use Explicit wait conditions which are

Tags:

Css Example