Unable to trigger mouse event in Capybara test

后端 未结 6 1484
Happy的楠姐
Happy的楠姐 2021-02-12 13:15

I am using Capybara 1.0.0, and I have a link in my page which gets visible when mouse hover over that block. So I want to trigger mouse over in test so that I can click that hid

6条回答
  •  悲&欢浪女
    2021-02-12 13:43

    I had a lot of trouble getting this to work as well. There's a lot of conflicting information on the web. Here's how I did it:

    Setting: rails 3.2.1, capybara 1.1.2, rspec 2.8.0, selenium-webdriver 2.20.0

    page.execute_script "$('tr.user-#{user.id}').trigger('mouseover')"

    This will cause the previously hidden links to appear (by virtue of jQuery's hover function), which are then accessible for have_link and click_link.

    Note: you do not want to write page.evaluate_script as this won't work.


    Edit: Well I just realized that @kelly-sutton's solution is the same as mine. So I can confirm this.

提交回复
热议问题