← Back to Discord Forum

How to resize a specific selector

cynthia_15050posted in #help-playwright
Open in Discord

Hi everyone,

I am working on creating an automated test to resize a specific selector as shown in the video attached. However, I can't seem to find a feature to help achieve that. I have tried page.mouse.move(selectorPositionX, selectorPositionY). However it points to the selector but it does not move the selector.

Any help would be appreciated!


This thread is trying to answer question "How can I automate a test to resize a specific selector?"

14 replies

I think you'd need to wrap your .mouse.move calls by .mouse.down and .mouse.up. Would that help?


Hi @cserby_02195 , unfortunately I don't get what you mean. If you can give an example


hi @pavelfeldman , posted the question here. If you can kindly let me know how to go about it or tag someone who can help. Thanks

First get the drag button's position (x, y) by await dragBtn.boundingBox() When you get the x,y you can use await page.mouse.move(x, y) then do the mouse.down -> mouse.move(your final x,y position) -> mouse.up to mimic the resize actions


Hi @Bububu, thanks for the support. I have tried that but it does not move the btn.


const dragBtnBox = await dragBtn.boundingBox() await page.mouse.move(dragBtnBox.x, dragBtnBox.y) await page.mouse.down() await page.mouse.move(dragBtnBox.x -20, dragBtnBox.y) await page.mouse.up() expect((await dragBtn.boundingBox()).x).toBe(dragBtnBox.x-20)

This the code I used

To reproduce the action precisely you have to check if top left position of the element can be hold manually or not. For stability you can just move to box.x + box.width/2 and same for y to get the center of the element


Hi @Bububu , I tried that but it does not work as well😫

Can you share the dom?

When you are doing this operation manually, you press the mouse button, move the element, and then release the mouse. That is 3 operations. Your code is only doing the second operation and missing first (mouse click and hold) and third (release).


Hi @Bububu and @ethenhunt, thanks for the support. I have been able to move it by changing the first and second mouse.move():

const sourceX = dragBtnBox.x + dragBtnBox.width/2 const sourceY = dragBtnBox.y + dragBtnBox.height/2 await page.mouse.move(sourceX, sourceY) await page.mouse.move(sourceX, sourceY) await page.mouse.down() await page.mouse.move(dragBtnBox.x, sourceY) await page.mouse.up()

However, this only moves up to the dragBtnBox.x location. When I try to do move it bellow(dragBtnBox.x -20), it does not work. How can i share the dom @Bububu ?

Trying to understand, why is this code present twice?

await page.mouse.move(sourceX, sourceY)```

ooh please ignore the second one @ethenhunt

-20 is move to the left i guess you can’t do it at first right? Try + 20 to mimic actions like in the video you recorded

Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.