How to work with hidden buttons, when you have to click without using id? - TestingQ.com

-->Exclusive Portal for Testing Jobs

How to work with hidden buttons, when you have to click without using id?

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

For example:
document.getElementsByClassName('post-tag')[0].click();

The above javascript would click, even if it is hidden (hypothetically).


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

(JavascriptExecutor(webdriver)).executeScript("document.getElementsByClassName('post-tag')[0].click();");

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.




To receive daily posted JOBS & Interview Questions
Just enter your email address below and click 'Submit'
Enter your email address:

Make sure to activate your subscription by clicking on the activation link sent to your email