Rayrun
← Back to Discord Forum

How to resize a specific selector

cynthia_15050posted in #help-playwright
Open in Discord
cynthia_15050

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!

Thanks

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

14 replies
cserby_02195

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

cynthia_15050

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

cynthia_15050

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

cynthia_15050

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

cynthia_15050

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

cynthia_15050

Hi @bububu8615 , 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).

cynthia_15050

Hi @bububu8615 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 @bububu8615 ?

Trying to understand, why is this code present twice?

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

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

TwitterGitHubLinkedIn
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 [email protected].