Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drag_to clicks links #2580

Open
boris-petrov opened this issue Sep 5, 2022 · 3 comments
Open

drag_to clicks links #2580

boris-petrov opened this issue Sep 5, 2022 · 3 comments

Comments

@boris-petrov
Copy link

Meta

Capybara Version:
3.37.1
Driver Information (and browser if relevant):
Selenium 4.2.1 on Chrome 105

Expected Behavior

Calling drag_to on a link causes Capybara to first drag/drop it and then click it. I don't understand why it would click it but that's what happens. It shouldn't.

Actual Behavior

The link is clicked.

Steps to reproduce

require 'capybara/dsl'
require 'selenium/webdriver'

html = DATA.read
app = proc { [200, { 'Content-Type' => 'text/html' }, [html]] }

sess = Capybara::Session.new(:selenium_chrome, app)
sess.visit('/')
sess.find_link.drag_to(sess.find('div'))
puts sess.has_css?('div', exact_text: 'qwe')

__END__
<html>
  <body>
    <a href="https://google.com" draggable>foo</a>
    <div>qwe</div>
  </body>
</html>

Run this. The drag_to line causes a transition to google.com. Then has_css? fails (as it's on a different page).

@twalpole
Copy link
Member

twalpole commented Sep 5, 2022

Not much that can be done about this. Capybara doesn't send a click event, it sends the HTML5 drag events (since an A element is by default draggable) -- then either the driver or the browser is interpreting the release of the mouse after dragging as a click

@boris-petrov
Copy link
Author

I don't think it's the browser because 1) doing such a drag and drop manually doesn't cause a transition and 2) I used to use my own implementation of such a functionality which works fine. Perhaps the problem is in click_and_hold and then release? I would be surprised for that to be a bug in Selenium though - no one to have hit such a problem.

@percyhanna
Copy link

I've seen this in the past specifically on CI. The issue seems to be that if the drag_to element is not an actual drop handler, the browser ends up sending a click instead of a drag. It seems to be that the mouse doesn't actually move/drag to that point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants