Site Loader
Auckland, New Zealand
In this post we will discuss how to work with hidden controls using Selenium with Javascriptexecutor, which is an interface found in Selenium package itself.

Hidden Controls

Hidden controls in a page is very common and they will be enabled only if certain criteria or conditions are met. There are many such real world scenario available like
  • Showing an button
  • Showing an label message etc

How will it look in code

In code they will be either hidden by using an HTML attribute called hidden or using CSS display property to none as shown below
<button id="clickme" style="display: none;" onclick="myFunction()" >Try it</button>
Here is the complete video of the above discussion Here is the complete code from the above video
public class hiddenControl {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		WebDriver driver = new FirefoxDriver();


		JavascriptExecutor js = (JavascriptExecutor) driver;
		WebElement hiddenButton = driver.findElement(By.xpath("//button"));
		String script = "arguments[0].click();";

		js.executeScript(script, hiddenButton);


Thanks for reading the post and watching the video !!! Please leave your comments and let me know if there is anything I should update in this post. Thanks, Karthik KK

Post Author: Karthik kk

Leave a Reply

Your email address will not be published. Required fields are marked *