0

I have an element that fires some javascript on click. Partially covering the element is a mostly-transparent graphic, which passes all events to that element. This way, regardless of if the overlay or the element is clicked, the element gets the events.

I'm trying to write a test in selenium that clicks the element under test and verifies the behavior, however the chrome webdriver tells me it can't click the element because the overlay will get the click event.

That is fine, though... How do I tell selenium that I don't care, to click anyways? I don't want to specifically click the overlay (in this test), the overlay is just eye-candy so the test should still work even if I remove the overlay.

edit: To make clear... I want it to click in wherever it would have, if the overlay wasn't there. this way it'll click the element if there is no overlay, but click the overlay if covered.

Bryan Hart
  • 583
  • 1
  • 5
  • 11
  • 2
    I haven't written the code so I'm just guessing by the docs. I'm not sure this will work. I'll assume you're using the Java version. You can try moving to the element's location using the `Actions#moveToElement` method and then `Actions#click` to click at the position. Here's the [relevant javadoc](http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/interactions/Actions.html). You should be able to find the equivalent in any other language. Let me know if this helps. – toniedzwiedz Apr 01 '14 at 18:27
  • @Tom that could work... maybe I'll override the click method to do that, or something. I'll give that a try, thanks! – Bryan Hart Apr 01 '14 at 19:27

3 Answers3

2

You will not be able to click on the object under the overlay as Selenium has been written to only access what a user can access. If a manual user cannot click through then neither can Selenium.

You could either fire JavaScript directly on that object via the javascript_executor method, or alternatively, perform the interaction which will remove the overlay in your test

Robbie Wareham
  • 3,380
  • 1
  • 20
  • 38
  • I realize that selenium won't be able to click on that element, but that doesn't matter. I want it to click on that _spot_, as though it _could_ click on the element. – Bryan Hart Apr 01 '14 at 19:18
  • @BryanHart: As RobbiWareham stated if user cant Selenium cant doesnt matter what you want – Ajinkya Apr 02 '14 at 05:33
  • 1
    @Bryan, I think Tom's idea is your only way. Not sure what will happen though. If you just want to prove it is not clickable, then there are other attributes and methods you could use – Robbie Wareham Apr 02 '14 at 06:26
  • @RobbieWareham I'll give Tom's suggestion a try, and if that doesn't work I'll just fire the javascript event as you suggested. I don't want to prove the element is not clickable... I want to prove that if the user clicks where they normally would, regardless of if the overlay is there or not, the expected behavior will happen. thanks! – Bryan Hart Apr 02 '14 at 14:07
0

I could resolve this issue: In my application top header was visible and i clicked on one of the top elements (which was visible) and could continue with rest of the script execution

0

I solved this issue by clicking the coordinates of the close button.

Check out this answer. I showed how to click on the little "x" there, without needing to know the name of the actual button. Sometimes its easier to find the class of the image, for example.

Worst case, find the closest element to the button and change the last method to move_to_element_with_offset(element,x, y) to go from the element you found to the coordinates of the button on screen.

Once you do that, the overlay disappears and you can click as normal.