Selenium WebDriver clicking on hidden element


Hi I would like to know how to click on hidden element and/or disable element by using Selenium WebDriver.

I know with selenium 1 I can do this as below:"idOfHiddenField");

and this would work, but with selenium 2 (WebDriver), this doesn’t. I do not want to use jquery to enable or show hidden fields , or JavaScript. This is because most of the test are using xpath.

Or do I just have to stay with old selenium which allows you to click on hidden fields?

  • You must to post comments

There is a easier way to work around the problem using JavascriptExecutor.

For example:


The above javascript would click on the “Selenium” tag on the top right of this page (next to your question), even if it were hidden (hypothetically).

All you need to do is issue this JS instruction via the JavascriptExecutor interface like so:


This would use the JS sandbox and synthetic click event to perform the click action. Although it defeats the purpose of WebDriver user activity simulation, you can use it in niche scenarios like in your case to good effect.

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.