Cameron Bass Cameron Bass - 9 months ago 81
Ruby Question

node.trigger("click") - Capybara

I have an element I'd like to use this on node.trigger("click") but I'm not sure how to find the element. it is a

and I'm relatively new to integration tests os I'm trying to find a answer to this question.

Here is the element

<%= link_to '✚ Invite Another Team Member', "#email", data: { invitation_modal_add: "" } %>

Here is my test I'd like to change.

click_link "✚ Invite Another Team Member"

Id like to replace that with something like this


Because that is what capybara is telling me to try at the moment because I'm getting this error

Firing a click at co-ordinates [0, 0] failed. Poltergeist detected another element with CSS selector ' body.accounts.users.index div.jquery-modal.blocker' at this position. It may be overlapping the element you are trying to interact with. If you don't care about overlapping elements, try using node.trigger('click').

Answer Source

To find the element you can just do

link = find(:link, "✚ Invite Another Team Member")

However before you start using trigger you should read the part of the error message before that - "if you don't care about overlapping elements". If you're actually testing your app you probably do care about overlapping elements since they can prevent your user from actually being able to click the link, and the fact that it's trying to click the link at 0,0 may indicate an issue with your page layout. You should probably try setting a larger window size (window_size option when registering your driver - so the link is not overlapped, make sure the link isn't fully hidden/collapsed in some way, or use execute_script with JS to scroll the page so the element becomes interactable. If you really don't care about a user actually being able to click the link then feel free to use #trigger