Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.7k points)

I am using Selenium 2 Java API with FirefoxDriver. When I fill a form, checkboxes are added to the page depending on the forms inputs.

I'd like to simulate a click on those checkboxes using Selenium. The element is visible and usable in a regular browser but, selenium asserts that the elements are not visible.

Element is not currently visible and so may not be interacted with

Can I force selenium to ignore the non-visible state of the elements? How can I force Selenium to interact with the non-visible element?

1 Answer

0 votes
by (62.9k points)

Selenium determines an element is visible or not by the following criteria (use a DOM inspector to determine what CSS applies to your element, make sure you look at computed style):

  • visibility != hidden
  • display != none (is also checked against every parent element)
  • opacity != 0 (this is not checked for clicking an element)
  • height and width are both > 0
  • for an input, the attribute type != hidden

Your element is matching one of those criteria. If you do not have the ability to change the styling of the element, here is how you can forcefully do it with javascript (going to assume WebDriver since you said Selenium2 API):

((JavascriptExecutor)driver).executeScript("arguments[0].checked = true;", inputElement);

But that won't fire a javascript event, if you depend on the change event for that input you'll have to fire it too (many ways to do that, easiest to use whatever javascript library is loaded on that page).

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium certification!

Browse Categories