Cypress - 单击、移动、释放鼠标操作

问题描述 投票:0回答:2

我想通过Cypress模拟鼠标功能(点击,按住(移动)和释放)来创建时间段(点击鼠标并选择几个小时的区块)Timeslot_web_element

我尝试过用鼠标移动触发器(鼠标按下、鼠标向上...)。

我已经尝试过:

cy.get(':nth-child(36) > .fc-timegrid-slot-lane')
.trigger('mousedown', { which: 1, pageX: 684.625, pageY: 704.188 })
.trigger('mousemove', { which: 1, pageX: 762.875, pageY: 782.438 })
.trigger('mouseup')

没有成功。

Test result

我使用赛普拉斯12.7

请问有什么想法吗?

谢谢

cypress
2个回答
1
投票

尝试使用{force: true}。我在错误中看到您的元素被另一个元素覆盖。

cy.get(':nth-child(36) > .fc-timegrid-slot-lane')
.trigger('mousedown', { which: 1, pageX: 684.625, pageY: 704.188 }, {force: true})
.trigger('mousemove', { which: 1, pageX: 762.875, pageY: 782.438 }, {force: true})
.trigger('mouseup')

0
投票

我不确定这个问题是否仍未解决,但我尝试了很多次,这个解决方案对我有用:(Cypress v13.3.2)

cy.get('tr td[data-time="12:00:00"].fc-timegrid-slot-lane').should('be.visible')
    .trigger('mousedown', 47.3, 13, { button: 0 }).wait(1000)

cy.get('tr td[data-time="13:00:00"].fc-timegrid-slot-lane')
    .trigger('mousemove', 47.3, 13, { force: true })
    .trigger('mouseup', 47.3, 13, { force: true })

其中代码的含义是:

cy.get('your element')
    .trigger('event', exactPosXInElement, exactPosYInElement, { options (left button, forced action) })

这就是我的应用程序中的样子: Test screenshot

© www.soinside.com 2019 - 2024. All rights reserved.