Joris
Joris

Reputation: 6305

How to click at a certain location in div

I want to execute a click on a full-screen div which is underneath a (non full-screen) modal dialog. However it seems that the click event automatically targets the center of my background div, thereby touching content that's on top of that div (the modal dialog itself).

How can I specify where the click should happen?

This is the verbose output of my click command:

Element is not clickable at point (640, 436). Other element would receive the click: <label class="btn btn-default ">...

Upvotes: 4

Views: 3586

Answers (1)

Anton Golinko
Anton Golinko

Reputation: 91

The root of problem is selenium clicks by sending mouseclick event not directly to the element but by screen coordinates. Therefore it cannot find clickable element by point (as described in verbose output).

There are two possible workaround (for your case):

1) Click by element position which not overlapped by modal dialog (applicaple for fullscreen div):

.moveToElement('.backdrop', 900, 10) // 900 is X offset
.mouseButtonClick(0)

2) Better, universal solution. By directily sending click event via injected javascript:

.execute(function(selector) {
      document.querySelector(selector).click();
   }, ['.backdrop'])

Upvotes: 6

Related Questions