- Jan 19, 2019
- admin
- 0
ElementNotVisibleException – Clicking Hidden Elements
A hidden element is not clickable on web page. There are certain CSS properties you may find on web page which makes the element non-visible as given below:
style = “display: none;”
style = “visibility: hidden;”
style = “height: 0px”
To overcome this issue, you may try JavaScript Executor provided by Selenium WebDriver
WebElement element = driver.findElement(By.xpath(“//div[@class=’container’]/div”));
((JavascriptExecutor) driver).executeScript(“arguement[0].click();”, element);
If this does’nt work, inject the script (which is not a good practice) to make this element visible something like this:
String script = “arguments[0].style.height=’auto’; arguments[0].style.visibility=’visible’;”;
and pass it in JavaScript Executor
((JavascriptExecutor) driver).executeScript(script, element);
then finally,
element.click();
And there you go !! You have clicked an hidden element
Happy Testing !!