Selenium - Check if an element is under another one

Viewed 8099

I'm using Selenium to do Java test. I know that i can check if an element is enable or displayed with this :

 isDisplayed
 isEnabled

Is it possible to check if an element is not visible, in the case that this element is under another ? For example, if a div is under another one. With that i want to check GUI element. For example if a button move under element, etc ...

Any ideas ?

thanks for helping _

4 Answers

Lets say you want to click an element, but that element is "behind"/"below" (aka 'obstructed' by anlother element), Selenium will actually throw a ElementClickIntercepted exception. As part of the exception message, it also returns which point you tried to click and which other element (tag, class) did intercept the click. By simply attemping to click an element and specifically catching this type of exception, you get the information you're looking for, if you catch such an exception => element not clickable (at the given coordinates - in most cases the default click point (or if you use actions: the offset you define)), if no exception => element is clickable.

The solution for Python is here.

It should be easy to convert it to Java.

Related